c
  1. c-program-to-find-factorial-of-a-number-using-recursion

Program to Find Factorial of a Number Using Recursion - ( C Programs )

Example:

Input: 5

Output: Factorial of 5 = 120

Explanation:

In this program, we are using recursion to find the factorial of a given number.

Factorial of a number n is the product of all positive integers less than or equal to n. For example, the factorial of 5 is 5 * 4 * 3 * 2 * 1 = 120.

To find the factorial of a given number using recursion, we need to follow these steps:

  1. We define a function factorial() that takes an integer n as input.

  2. In this function, we first check if n is equal to 0 or 1. If it is, then we return 1, as the factorial of 0 and 1 is always 1.

  3. If n is greater than 1, then we call the same function recursively with n-1 as the input parameter.

  4. The function continues to call itself recursively until n becomes 1 or 0.

  5. When n becomes 1 or 0, the function returns 1.

  6. Finally, the main function calls the factorial() function and prints the result.

Usage:

This program can be used to find the factorial of a given number. It demonstrates the use of recursion in C programming.

Summary:

This program uses recursion to find the factorial of a given number. It showcases the use of recursive functions in C programming. The program is simple and straightforward, making it a great starting point for anyone interested in learning about recursion in C programming.

Published on: