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

Still curious? Ask our experts.

Chat with our AI personalities

MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao

Add your answer:

Earn +20 pts
Q: Program to find n th fabonacci number?
Write your answer...
Submit
Still have questions?
magnify glass
imp