c++ program for factorial of a number using recursion
#include<iostream>
using namespace std;
long fact(int num);
int main()
{
int num;
cout<<"Enter number for factorial ";
cin>> num;
cout<<"Factorial of "<< num <<endl<<fact(num);
}
long fact(int num)
{
if(num==0)
return 1;
else
{
return (num*fact(num-1));
}
}
using namespace std;
long fact(int num);
int main()
{
int num;
cout<<"Enter number for factorial ";
cin>> num;
cout<<"Factorial of "<< num <<endl<<fact(num);
}
long fact(int num)
{
if(num==0)
return 1;
else
{
return (num*fact(num-1));
}
}
output-
Enter number for factorial 5
factorial of 5
120
Comments
Post a Comment