Program to find factorial using recursion in C++
#include<iostream.h>
#include<conio.h>
long int fact(int a)
{
long int res;
if(a>1)
{
res=a*fact(a-1);
return res;
}
else
return 1;
}
void main()
{
long int n,f;
clrscr();
cout<<"\nEnter number to find factorial :: ";
cin>>n;
f=fact(n);
cout<<"\nFactorial of "<<n<<" is "<<f;
getch();
}
OUTPUT::
Enter number to find factorial ::5
Factorial of 5 is 120.