I attempted question- small factorials (FCTRL2)( http://www.codechef.com/problems/FCTRL2 ) - but my code is giving wrong answer error and I cant get the error in my code … plz suggest how i can modify my code … my code is http://www.codechef.com/viewsolution/4466447
see here:
output seems to be 12 every time (would have been funnier if 42 kept coming out though)
A few ideas:
Break the problem down a little - your code is too interdependent on tracking variables like siz which are doing too many things. This is going to make debugging very hard.
See my code http://www.codechef.com/viewsolution/4465834, its not important whether you understand it (or rate it at all) but notice that I’ve broken the problem down so that I can test each part of the code separately. I also wrote it using a top down approach. I wrote the function factorial first, including the use of helper functions I hadn’t written yet, and then wrote the sub-functions after to make the code feel natural as possible.
Also, get out of the habit of using cin/cout for input/output. It doesn’t matter so much on this problem but your going to run into time exceeds on other problems if you don’t learn about scanf/printf in the library, which are quicker.
ok, the link i gave didn’t work (try http://ideone.com/pvKQIF) but just play about on ideone.com and you’ll see what I mean