C++ program to calculate the factorial of a number using recursion.

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

Write a program to calculate the factorial of a number using recursion.

#include<iostream.h>
#include<conio.h>
void main()
{
	int n,fact;
	int rec(int); clrscr();
	cout<<"Enter the number:->";
	cin>>n;
	fact=rec(n);
	cout<<endl<<"Factorial Result are:: "<<fact<<endl;
	getch();
}
rec(int x)
{
	int f;
	if(x==1)
		return(x);
	else
	{
		f=x*rec(x-1);
		return(f);
	}
}

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

26 Responses to “C++ program to calculate the factorial of a number using recursion.”

Leave a Reply