December 22, 2011

Many of you must have created a program to calculate the factorial of large numbers. You will use recursion, simple loop to calculate the factorial. The problem is not the method, problem comes up when I tell you to compute the factorial of the number 100. What ? is it easy ?

Okay, Do you know that factorial of 100 contains 24 zeros at the end only if we leave the middle ones. The problem is to how to store this long number.

Code:
/*C Program to calculate factorial of large numbers ~ MyCFiles.com*/

Code Analysis:
We created a program that can calculate the factorial of numbers 1 to 1,000. Yes. We have used array to store the large number. One condition of the program is that your compiler must be able to handle the array large enough to handle the factorial of 1,000. That’s why we used CodeBlock IDE the used GCC compiler. Anyways, if you clearly look at the program, you will see that program first stores all the factorials from 1 to 1,000 first, then asks you for Input. It is done because in some cases, you need to calculate the factorial in the given time limit. Believe me that if you are going to start from scratch, you are never going to end computing in time. But here is the trick, time starts from the instant you took the input, it means first compute the result of all the imputs, store it, then show it as wanted.
Use CodeBlock IDE because TC++ can’t handle large array size. Download CodeBlock mingw-setup from here.
If you are new to CodeBlock, I got certain things for you,
use Ctrl+F9 -> Compile
and use Ctrl+F10 -> Run