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

by Nideesh C on April 14, 2011 · 0 comments

in C++




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



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to find the factorial of a given number
  2. Sample – factorial
  3. Sample – Program to enter a sentence and output the number of uppercase & lowercase consonants, uppercase & lowercase vowels in sentence..
  4. Sample – Program to convert 2-digit octal number into binary number and print it.
  5. C program to create a file called emp.rec and store information about a person, in terms of his name, age and salary.

Leave a Comment

Previous post:

Next post: