answersLogoWhite

0

#include
#include

using std::cin;
using std::cout;
using std::endl;
using std::tolower;

long factorial(const int& N);

int main()
{
int N = 0; //factorial of N
char command = 'n';
do
{
cout << "Enter a number to calculate factorial: ";
cin >> N;

cout << endl << "Factorial of " << N << " is: " << factorial(N) << endl;

cout << "Do you want to continue (y/n)?";
cin >> command;
cout << endl;
} while ('y' == tolower(command));

system("PAUSE");
return 0;
}

long factorial(const int& N)
{
if (N == 0)
{
return 1;
}
else
{
return (N * factorial(N - 1));
}
}

User Avatar

Wiki User

15y ago

What else can I help you with?