c++ program for fibonacci 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