C FACTORIAL PROBLEM

**MY QUESTION=**http://www.codechef.com/problems/FCTRL2/
**MY SOLUTION=**http://www.codechef.com/viewsolution/4571855
**TYPE OF ERROR=**WRONG ANSWER

PLZ EXPLAIN MY FAULT AND DEBUG THE CODE

You have a few problems.

First, your factorial is not calculating properly. Try changing the loop from

for(j=2;j<=i;j++)

to

for(j=2;j<=a[i];j++)

(not the only approach).
Secondly, for factorials of large numbers, “int” data type or even “long” will fall short. For example,

0! 	 1  
 1! 	 1
 2! 	 2
 3! 	 6
 4! 	 24
 5! 	 120
 6! 	 720
 7! 	 5040
 8! 	 40320
 9! 	 362880
10! 	 3628800
11! 	 39916800
12! 	 479001600
13! 	 6227020800
14! 	 87178291200
15! 	 1307674368000
16! 	 20922789888000
17! 	 355687428096000
18! 	 6402373705728000
19! 	 121645100408832000
20! 	 2432902008176640000
21! 	 51090942171709440000
22! 	 1124000727777607680000
23! 	 25852016738884976640000
24! 	 620448401733239439360000
25! 	 15511210043330985984000000

So, as you can see, even long long int will not work for “n!” with a moderate value of n.
I suggest you to try some other data structure like array.

//