Wednesday, 28 December 2011

C program to find the factorial of a number using recursion



#include<stdio.h>
int fact(int);
main()
{
int n,temp;
printf("Enter a number\n");
scanf("%d",&n);
if(n>=0)
{
temp=fact(n);
printf("Factorial is %d",temp);
}
else
printf("Cannot find the factorial");
}

int fact(int c)
{
if(c==0)
return(1);
else
return(c*fact(c-1));
}



You Like It!? Then kindly share with your Friends.
Comments
0 Comments

No comments:

Post a Comment