A program to calculate the factorial of a given number using recursive function.
A program to calculate the factorial of a given number using recursive function.
Codes
/*A program to find the factorial of a number using recursive function*/
/*Programed by Jitendra Kr Yadav
10116
15 Mar,2011*/
#include<stdio.h>
#include<conio.h>
int rec(int);
main()
{
int fact,n;
printf(“Enter the number:”);
scanf(“%d”,&n);
fact=rec(n);
printf(“Factorial = %d\n\n”,fact);
printf(“Press any key to continue…”);
getch();
}
int rec(int a)
{
int f;
if(a==1)
return(1);
else
{
f=a*rec(a-1);
return(f);
}
}
Output
Enter the number: 5
Factorial = 120
Press any key to continue…