In this tutorial, we will discuss the C Program for calculating the factorial of a number using recursion
There are many ways to calculate factorial using C language and one of this given below – Using the recursive function in C language
In this article, we are going to learn how to calculate factorial of a number using the recursive function in C programming language
Factorial is a product of all positive descending integer begins with a specified number (n) and calculates up to one
Example
factorial of 5 is
5!=5*4*3*2*1=120
factorial of 4 is
4!=4*3*2*1=24
factorial of n is
n!=n*(n-1)*....2*1
Program
This program allows the user to enter a positive integer number and it calculates the factorial of the given number using the recursive function in C language
Program
#include <stdio.h> #include <stdlib.h> int factFind(int);//function prototype int main() { int num; //ask input from the user printf("Enter a positive integer\n"); //given value is stored in num variable scanf("%d",&num); //calling the findFact() function- user-defined int factorial=factFind(num); //displaying factorial of the given number printf("factorial of %d=%d",num, factorial); getch(); return 0; } int factFind(int num){//function definition if(num>=1) //function calling itself recursively return num*factFind(num-1); else return 1; }
The above code is executed. it produces the following result
Enter a positive integer 7 Factorial of 7=5040
Approach
To clearly understand this article, you should have the previous knowledge of the following C programming subject
The recursive function in C language
The function in C language
Similar post
Find factorial of a number in Java
Find factorial of a number in C language
Find factorial of a number in C++ language
Find factorial of a number in Python language
Find factorial of a number in Java using method
Find factorial of a number in C using the function
Find factorial of a number in C++ using the function
Find factorial of a number in Python using the function
Find factorial of a number using the pointer in C language
Find factorial of a number using the pointer in C++ language
Find factorial of a number using the recursion in C++ language
Find factorial of a number using the recursion in Java language
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…
Python code to Calculate sum of odd and even in a list In this tutorial,…
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…