The factorial of a negative number doesn't exist. And, the factorial of 0 is 1.
You will learn to find the factorial of a number using recursion in this example. Visit this page to learn, how you can find the factorial of a number using loop.
Example: Factorial of a Number Using Recursion
long int multiplyNumbers(int n);
printf("Enter a positive integer: ");
printf("Factorial of %d = %ld", n, multiplyNumbers(n));
long int multiplyNumbers(int n)
if (n >= 1)
Enter a positive integer: 6
Factorial of 6 = 720
Suppose the user entered 6.
Initially, the multiplyNumbers() is called from the main() function with 6 passed as an argument.
Then, 5 is passed to the multiplyNumbers() function from the same function (recursive call). In each recursive call, the value of argument n is decreased by 1.
When the value of n is less than 1, there is no recursive call.