write a factor program that repeatedly ask for a number betw

write a factor program that repeatedly ask for a number between 1-100 and calculate its factorial until user enters zero to terminate the probram. C++

Solution

#include using namespace std; int fact(int f); // function for getting factorial int main() { int f; while(f!=0) //while loop which runs until 0 is entered {cout << \"Enter a positive integer between 0-100: \"; cin >> f; } cout << \"Factorial of \" << f << \" = \" << fact(f); //goes to function factorial return 0; } int fact(int f) { if(f > 1 && f< 100 ) return f * factorial(f - 1); //recursive function for getting the factorial else return 1; }
write a factor program that repeatedly ask for a number between 1-100 and calculate its factorial until user enters zero to terminate the probram. C++Solution #

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site