# Find Factorial of Number C Program

## C Program To Find Factorial of Number

Learn How To Find Factorial of Number in C Programming Language. It is important that we should know about** How A For Loop Works **before getting further with the C Program Code. This Code is described with an Explanation of Factorial Program in C Language. We have used Recursion method as well as the While and For Loops in the following Factorial Programs.

#### 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. The Factorial Notation is used in Combinatorics, Permutations, Algebra and other Mathematical Analysis.

#### Example

**5! = 5 * 4 * 3 * 2 * 1 = 120**

One interesting thing to note here is that the value of **0! = 1**.

**Must Read: C Program To Find Factorial of Large Numbers**

#### Method 1: Calculate Factorial of Number in C with While Loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include<stdio.h> void main() { int num, count, fact = 1; printf("\nEnter a Number:\t"); scanf("%d", &num); count = num; while(count >= 1) { fact = fact * count; count--; } printf("\nFactorial of %d is %d\n", num, fact); } |

**Must Read: C Program To Display Fibonacci Series**

#### Method 2: C Program To Find Factorial of a Number using For Loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include<stdio.h> int main() { int num, count, fact = 1; printf("\nEnter a Number:\n"); scanf("%d", &num); for(count = num; count >= 1; count--) { fact = fact * count; } printf("\nFactorial of %d is %d\n", num, fact); return 0; } |

**Must Read: C Program To Find Greatest Common Divisor of Two Numbers**

#### Method 3: C Program To Calculate Factorial using Recursion Method

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include<stdio.h> int factorial_recursion(int x); int main() { int var, check; printf("\nEnter a Number:\t"); scanf("%d", &var); check = factorial_recursion(var); if(res == check) { printf("\nFactorial of %d is %d\n", var, check); } else { printf("\nFactorial of %d is %d\n", var, check); } return 0; } int factorial_recursion(int m) { if(m == 1) return m; else return (m*factorial_recursion(m - 1)); } |

**Must Read: C Program To Calculate Value of nPr in Probability**

#### Output

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

Thanks for so many ways to solve factorial program in c programming. Helped to match differences between for and while loops.

You’re welcome Dipak! Our main aim was to make the readers understand Factorial of a Number C Program effectively using comparison!!

I finally learnt how to convert a For Loop into a While Loop in C Programming.

Can we use separate funtion to write factorial program in C language?

Can we make a library function for factorial of a number c program which cam be used by including header files?

Can we find Factorial of a very large integer number using the same code above?

No. A large integer will require a datatype having larger range than just an

int. This code is sufficient only for finding factorial of a normal number.Please provide Factorial of Large Numbers in C Programming.