#include
long factorial(int);
int main();
{
int n; //declares variables to be used in program
long f;
print f(“Enter a positive integer value of N: \n”); //gets input from the user
scanf(“%d”, &n); //reads the input from the user and assigns the value to n
if (n < 0) //checks to see if n is positive or negative
{
printf(“Negative integers are not allowed. Please rerun the program using a positive integer. \n”);
}
else
{
f = factorial(n); //calls recursive factorial function
printf(“The value of factorial of %d is %ld\n”, n, f); //outputs the result
}
}
long factorial(int n)
{
if (n == 0) //if the value is 0, the factorial is 1
{
return 1;
}
else //calculates the factorial for any non zero positive integer value for n
{
return(n * factorial(n – 1));
}
}