Getting WA in SPOJ AMR11A

I am getting WA verdict in this problem and am unable to figure out why! It would be great if someone can point out the flaw in my approach or suggest correct approach.
Here’s the link to my code : Link
Thanks :slight_smile:

Please help somebody!