Saturday, March 10, 2012

Write a C program to find the factorial of a number using recursion.

#include
#include
int fact(int);
void main()
{
int num,fact1;
printf("Enter a value of num");
scanf("%d",&num);
fact1=fact(num);
printf("factorial=%d",fact1);
getch();
}
int fact(int n)
{
int f=1;
if(n==0)
{
return 1;
}
else
{
f=n*fact(n-1);
return(f);
}
}

No comments:

Post a Comment