#include <iostream.h> int factorial(int); int main() { int number=5; if (number < 0) cout << "That is not a positive integer.\n"; else cout << number << " factorial is: " << factorial(number) << endl; } int factorial(int number) { int temp; if(number <= 1) return 1; temp = number * factorial(number - 1); return temp; }
Recursive Factorial Example Program
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment