Find factorial using recursion - C Program

Write a recursive function to print factorial of number.

OR

Write a C Program to calculate factorial of given number by using recursion.


Solution:

#include <stdio.h>
long fact(int n)
{
     if(n==1)
          return 1;
     else
          return(n*fact(n-1));
}
int main()
{
     long a,z;
     printf("Enter Number : ");
     scanf("%ld",&a);
     z=fact(a);
     printf("\nFactorial of %ld : %ld",a,z);
     return 0;
}


Output:

factorial using recursion