/**************************************************
Program to calculate Factorial using recursion
*
* Enter a number: 4
* 4! = 24
***************************************************/
#include<stdio.h> // include stdio.h library
long factorial(int num);
int main(void)
{
int n;
printf("Enter a number: \n");
scanf("%d", &n);
printf("%d! = %ld", n, factorial(n));
return 0; // return 0 to operating system
}
long factorial(int num)
{
//base condition
if(num == 0)
{
return 1;
}
else
{
// recursive call
return num * factorial(num - 1);
}
}