Skip to content

Instantly share code, notes, and snippets.

@Manume
Created May 21, 2014 09:01
Show Gist options
  • Select an option

  • Save Manume/45a624fb15f0fe0369ad to your computer and use it in GitHub Desktop.

Select an option

Save Manume/45a624fb15f0fe0369ad to your computer and use it in GitHub Desktop.
program for finding factorial
#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