# Factorial of Large Numbers C Program

## C Program To Find Factorial of Large Numbers using Arrays

Learn How to Find Factorial of Large Numbers in C Programming Language. This C code uses Arrays to store Intermediate results while calculating factorial of a Big Number. A factorial is the product of an Integer with all the Integers less than it till 1, considering the number is Positive.

There are some restrictions in the normal method to **Calculate Factorial of an Integer in C Programming. **For normal Integers like 5, 10, 20, factorial can be found out easily but if you try to find out factorial of 100 or greater numbers, this code won’t show you the correct output.

It is because the range of factorial of 100 is quite larger than the range of an integer datatype. Therefore, we shall use Array **data structure** to store the Intermediate results of calculating factorial of a given Big Integer.

#### Algorithm to Calculate Factorial of a Large Number

- Create an Array variable with a large Dimension such as 400 or 500 so that if the Factorial result is 500 Numbers long, we will be able to display it in the output efficiently.
- Initialize the Array variable with 1 and initialize a limit variable with 1 too.
- Perform the following calculation from a = 2 to Number
- Multiply a with array variable and update the Limit and Array variable simultaneously.

#### Example

**120**

6689502913449127057588118054090372586752746333138029810295671352301633557244962989366874165271984981308157637893214090552534408589408121859898481114389650005964960521256960000000000000000000000000000

**Must Read: C Program To Print Map of India**

#### C Program To Find Factorial of Large Numbers using Arrays

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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include<stdio.h> void calculate_factorial(int num); int multiplier_function(int a, int array[], int limit); int main() { int num; printf("\nEnter a Number:\t"); scanf("%d", &num); calculate_factorial(num); printf("\n"); return 0; } void calculate_factorial(int num) { int array[500]; array[0] = 1; int count, a, limit = 1; for(a = 2; a <= num; a++) { limit = multiplier_function(a, array, limit); } printf("\nFactorial of the Number:\n"); for(count = limit - 1; count >= 0; count--) { printf("%d", array[count]); } } int multiplier_function(int a, int array[], int limit) { int count, product, temp = 0; for(count = 0; count < limit; count++) { product = array[count] * a + temp; array[count] = product % 10; temp = product / 10; } while(temp) { array[limit] = temp % 10; temp = temp / 10; limit++; } return limit; } |

#### Output

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

Wow! I had not thought about such a concept. Thanks for posting this Factorial of Large Number code.

Thanks for the algorithm of factorial of a large number i needed this more than the c program.

I dont think there is any other datatype for storing such a large number, Isn’t it?