Friday, 10 March 2017

C++ program of recursion

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:

Share: