The following code prints the factorial of a number. You can find the explanation of the code in the Recursion section of https://www.codesdope.com/c-my-functions/.
#include <stdio.h>
int factorial( int a ) /* function */
{
if( a == 0 || a == 1)
{
return 1;
}
else
{
return a*factorial(a-1);
}
}
int main()
{
int n;
printf("Enter number\n");
scanf("%d", &n);
int fact = factorial(n);
printf("Factorial of %d is %d\n", n, fact);
return 0;
}