Hi,
I am working on a program that asks a user to enter a # between 1 to 50 and finds the factorial of that. It uses recursive function to find it.
Here is what I got so far:
Its not working, can some please help me solve this problem.Code:include <iostream> using namespace std; //function prototypes int getNum(); int fact(int); void printResult(int, int); int main() { int num; int ans; num = getNum(); ans = fact(num); printResult(num, ans); cout << endl << endl; } int getNum() { int num; cout << "\nEnter a number:"; cin >> num; return num; } int fact(int num) { if (num == 0) return 1; else return num * fact(num - 1); } void printResults(int num, int ans) { cout <<"\nfactorial of" << num << "is : " << ans; }
Thanks



LinkBack URL
About LinkBacks


