Factorial Using Recursion


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.


-----

Firoz Memon

Please view my other blogs:

          C++ Codes 4 Beginners

          Java Tips

          Java 4 Beginners

Previous Post Next Post