//To input a number and calculate its factorial using recursion.
#include
#include
long int fact(int);
main()
{
int i,n;
long int f;
clrscr();
printf("Input a number : ");
scanf("%d",&n);
f=fact(n);
printf("\nFactorial of %d is %ld",n,f);
}
long int fact(int m)
{
long int f;
if(m<=1)
return(1);
else
f=m*fact(m-1);
return(f);
}
No comments:
Post a Comment