PROGRAM TO FIND
FACTORIAL OF A GIVEN NUMBER USING RECURSION
#include<stdio.h>
main()
{
int f,n;
printf("Enter the value for finding
factorial\n");
scanf("%d",&n);
f=fact(n);
printf("Factorial of %d is %d\n",n,f);
}
int fact(int a)
{
int fa;
if(a==1||a==0)
return 1;
else
fa=a*fact(a-1);
}
~
~
"factrec.c" 20L, 243C
13,1 All
OUTPUT:
"factrec.c" 20L, 243C written
[staff@linuxserver staff]$ ./a.out
Enter the value for finding factorial
7
Factorial of 7 is 5040
[staff@linuxserver staff]$
No comments:
Post a Comment