Created
May 21, 2014 09:01
-
-
Save Manume/45a624fb15f0fe0369ad to your computer and use it in GitHub Desktop.
program for finding factorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream.h> | |
| int fact (int i) { | |
| int result = 1; | |
| while (i > 0) { | |
| result = result * i; | |
| i = i-1; | |
| } | |
| return(result); | |
| } | |
| int main () { | |
| int n; | |
| cout << "Enter a natural number: "; | |
| cin >> n; | |
| while (n < 0) { | |
| cout << "Please re-enter: "; | |
| cin >> n; | |
| } | |
| cout << n << "! = " << fact(n) << endl; | |
| return(0); | |
| getch(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment