C++ program to find Factorial of number using Recursion

//C++ program to find factorial of number using recursive function
#include <iostream>
using namespace std;
int fact(int a)
{
   if(a>1)
   {
      return a*fact(a-1);
   }
   else
   {
      return 1;
   }
}


int main()
 {
int num,num1;
cout<<"Enter a number to find its Factorial ";
cin>>num;
num1=fact(num);
cout<<"The factorial of the number "<<num<<" is = "<<num1;

return 0;
}

No comments:

Post a Comment