c++ program for factorial using recursion
Output:
enter a number to find its factorial
5
The factorial of 5 is 120
Implementation:
Output:
enter a number to find its factorial
5
The factorial of 5 is 120
Implementation:
#include <iostream>
using namespace std;
int fact(int n)
{
if(n==0 || n==1)
return 1;
return n*fact(n-1);
}
int main() {
int n;
cout<<"enter a number to find its factorial"<<endl;
cin>>n;
cout<<"The factorial of "<< n <<" is "<< fact(n) <<endl;
return 0;
}