Find Factorial using Recursion C Program

By | December 10, 2015

C Program To Find Factorial using Recursion

Learn How To Find Factorial using Recursion in C Programming Language. It is important that we should know How A For Loop Works before getting further with the C Program.

What is a Factorial of a Number?

A Factorial for a Non-Negative Integer is the Product of all the Positive Integers Less than or Equal to that Number.

Example

4! = 4 * 3 * 2 * 1

Also Read: C Program To Find Factorial of a Number using For Loop

Note: This C Program to Find Factorial of a Number using Recursion method has been compiled with GNU GCC Compiler and developed with gEdit Editor and Terminal in Linux Ubuntu Operating System.

C Program To Find Factorial using Recursion

#include<stdio.h>

int factorial(int x);

int main()
{
      int num, res;
      printf("\nEnter a Number:\t");
      scanf("%d", &num);
      res = factorial(num);
      if(res == num)
      {
            printf("\nFactorial of %d is %d\n", num, res);
      }
      else
      {
            printf("\nFactorial of %d is %d\n", num, res);
      }
      return 0;
}

int factorial(int x)
{
      if(x == 1)
            return x;
      else
            return (x*factorial(x - 1));
}

Also Read: C Program To Find Sum of Digits of Number using Recursion

 

Output

Find Factorial using Recursion in C Programming

Also Read: C Program To Print Fibonacci Series using Recursion

 

If you have any compilation errors or doubts in this C Program To Find Factorial of a Number using Recursion, let us know about in the Comment Section below.

Let's Discuss