## 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

#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

#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

#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.

This program for factorial can contain one additional if loop. Since, the factorial of 1! is 1 and the factorial of 0! is 1, it needs to be implemented in this factorial code too.

if(n == 0 || n == 1)

{

fact = 1;

}

Best explanation of the factorial of a number in C programming. This has cleared my concepts and especially the loops in C.