C Example | Implement Factorial Recursion

This c example code shows how to implement factorial recursion by given a number.

#include <stdio.h>
long int multiplyNumbers(int n);

int main()
{
 int n; //variable declaration
 
 printf("Enter a positive number: "); //asking user to enter number
 
 scanf("%d", &n); //reading number from user
 
 printf("Factorial of %d = %ld", n, multiplyNumbers(n));
 return 0;
}

//Recursive function for finding factorial

long int multiplyNumbers(int n)
{
 if (n >= 1)
 return n*multiplyNumbers(n-1);
 else
 return 1;
}

Run this code:

Enter a positive number: 5
Factorial of 5 = 120