/*program
to show the factorial of any number which is inputed by the user by recurtion*/
void
main()
{
int
a;long int c=1,f;
clrscr();
printf("Enter
any number to know its factorial ");
scanf("%d",&a);
f=fact(a,1,c);
printf("\nFactorial
of %d is %ld ",a,f);
getch();
}
fact(int
a,int b,long int c)
{
if(b<=a)
{
c=c*b;
return
fact(a,(b+1),c);
}
return
c;
}
Output
Enter
any number to know its factorial 5
Factorial
of 5 is 120
No comments:
Post a Comment