spoj wrong answer

getting WA
link:http://www.spoj.com/problems/OAE/
here is my solution

your code gives wrong answer for the following case :-

correct code output

your code output

i want to know what is wrong with my logic