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

Screenshot (3).png

}

int main()

{

int m;

cout<<“Enter value to find factorial : “;

cin>>m;

cout<<rf(m);

getch();

}

//Code ends

OUTPUT:

Screenshot (3).png

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s