Monday, 6 May 2013

RECURSIVE PROGRAM FOR FACTORIAL CALCULATION

Factorial of any positive number n, denoted by n!, is the product of all integers from 1 till n.

n! = 1*2*3*4*.............*(n-2)*(n-1)*(n)




Recursive definition :-
F(n) = F(n-1) * n


Source code:-
/********************************************************************************/ 

#include<stdio.h>
#include<conio.h>

long factorial(int);


int main()
{
int num;
clrscr();
printf("ENTER THE NUMBER : ");
scanf("%d",&num);

printf("FACTORIAL = %ld",factorial(num));
getch();
return 1;
}

long factorial(int fact)
{
long temp;
if(fact<=1)
return 1;

temp=fact*factorial(fact-1);
return temp;
}
/***************************************************************************/
Output:-


 
Other links for reference :-
 

 

No comments:

Post a Comment