232k views
2 votes
Write a c++ program to solve the factorial problem x! by creating a function that calls itself'

User Ansiart
by
8.5k points

1 Answer

2 votes
int factorial(int n)
{
if (n <= 1) {
return 1;
}
else {
return n* factorial(n - 1);
}
}

With recursive functions, always check that there is a certain end criterium. When n<=1, the recursion stops.
User SEMson
by
7.7k points

No related questions found