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));


}
}
output-
Enter number for factorial 5
factorial of 5
120

Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation