Getting a run time error. Help.

Can anyone help me with the code given below. The code is for the problem ‘small factorials’(FCTRL2) and the error which i am getting is runtime error. So please help.!!

The link to my code is : http://www.codechef.com/viewsolution/4147504

The runtime error is due to missing of statement “return 0”.Now coming to your algo, it’s wrong. As you need to calculate upto 100!, 100! factorial may have upto 200 digits even the long long also not sufficient to use , so try using character array.I think this link may help you :

http://discuss.codechef.com/questions/7349/computing-factorials-of-a-huge-number-in-cc-a-tutorial

1 Like

Your main function is void. That is the mistake-i mean for RUN TIME error. Your funtion should be int main(). Even if you are not returning any value it is okay. But the main function should not void main()

Now even if you change you code with int main() your code will not accepted. Check this


[1] and compare the result with your code for the test cases like 50! numbers like that. Your code will give some -ve numbers because of the over-flow in the data type. In c++ we dont have any-data type that can store very large numbers even  long long int can store numbers in the range 10^18.

But the above mentioned test cases will need more space than that. So you will have to store the answer in an array. Read [this][2] editorial or google how to find the factorial using array.

**Happy Coding** 


  [1]: http://ideone.com/jTDKP8
  [2]: http://discuss.codechef.com/questions/7349/computing-factorials-of-a-huge-number-in-cc-a-tutorial
1 Like

Thank you for answering, i will definitely go through the link you gave and will try again to get my code accepted.

Thank you Sir, for answering my doubt , it helped a lot. :slight_smile: :slight_smile:

Very helpful link, thank you once again.