Factorial Program in C / Find factorial using Recursion
What is Factorial?
In Mathematics, factorial is a simple thing. Factorials are just products. An exclamation mark indicates the factorial. Factorial is a multiplication operation of natural numbers with all the natural numbers that are less than it. In this article, let’s discuss the factorial definition, formula and examples.
The formula to find the factorial of a number is
n! = n × (n-1) × (n-2) × (n-3) × ….× 3 × 2 × 1
Factorial of 10
For example, the factorial of 10 is written as
10! = 10 (9 × 8 × 7 × 6 × 5× 4 × 3 × 2 × 1)
Therefore, the value of 10 factorial is 3,628,800
How to find factorial in C using loog
#include
int main()
{
int i,fact=1,number;
printf("Enter a number: ");
scanf("%d",&number);
for(i=1;i<=number;i++){
fact=fact*i;
}
printf("Factorial of %d is: %d",number,fact);
return 0;
}
Find factorial in C using Recursion
OUTPUT :
Enter a number: 5 Factorial of 5 is: 120
CONCLUSION :
There are multiple methods to calculate the factorial of a number in C. Whether it's using an iterative solution, recursion, the tgamma() method, or pointers, the most suitable method will depend on the specific needs of your program.