C++ Program To Find Factorial Of Two Numbers Using Recursion Function

#include<iostream>
using namespace std;
long int fact(int);
int main()
{
int n1,n2;
cout<<"Enter number"< cin>>n1>>n2;
cout<<n1<<"! = "<<fact(n1)<<endl;
cout<<n2<<"! = "<<fact(n2)<<endl;
}
long int fact(int n)
{
if(n<=1)
return 1;
else
  return (n*fact(n-1));
}

OUTPUT


Enter number
5
4
5! = 120
4! = 24
Share To:

Arogya Thapa Magar

Post A Comment:

0 comments so far,add yours