In this program we will clear the concept of recursion, that how a function calls it self and shows us the real value.
//Code Starts
#include<iostream>
#include<conio.h>
using namespace std;
int rf(int n)
{
if(n==1)
{
return 1;
}
else
{
return n*rf(n-1);
}
}
int main()
{
int m;
cout<<"Enter value to find factorial : ";
cin>>m;
cout<<rf(m);
getch();
}
//Code ends
OUTPUT:
//Code Starts
#include<iostream>
#include<conio.h>
using namespace std;
int rf(int n)
{
if(n==1)
{
return 1;
}
else
{
return n*rf(n-1);
}
}
int main()
{
int m;
cout<<"Enter value to find factorial : ";
cin>>m;
cout<<rf(m);
getch();
}
//Code ends
OUTPUT:
0 comments:
Post a Comment