Tuesday, December 30, 2014

C program to find factorial using Recursion

/*C program to find factorial using Recursion*/


#include<stdio.h>
#include<conio.h>
int fact(int);
int main()
{
int num,f;
printf("\nEnter a number: ");
scanf("%d",&num);
f=fact(num);
printf("\nFactorial of %d is: %d",num,f);
return 0;
}
int fact(int n)
{
if(n==1)
return 1;
else
return(n*fact(n-1));
}

No comments:

Post a Comment