Recursive version of factorial function in C

 
 #include <stdio.h>
 
 int fact(int);
 int main()
 {
     int y,n;
 
     printf("Enter the value of n: ");
     scanf("%d",&n);
     y=fact(n);
     printf("nFactorial of %d is %dn",n,y);
     return 0;
 }
 
 int fact(int n)
 {
     int f;
 
     if(n==1)
         return 1;
     f=fact(n-1)*n;
     return f;
 }

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.