getting a wrong answer message

Can anyone please tell me why am I getting a wrong answer message even though my prog correctly displays the output in the prescribed format for respective inputs ?
While this is rectified if I initialize my variables and then run the program.

it might be that your code is not covering all possible cases or it is printing anything that is not required

Always provide the problem link and the solution link while asking about a doubt in a problem.

Looking at your profile, you seem to be talking about these solutions.

https://www.codechef.com/viewsolution/14554224

https://www.codechef.com/viewsolution/14554416

The problem is that you are using variable num to store the count of numbers and it is not initialized to 0. Local variables that are uninitialized take garbage values by default. Thus, the code with uninitialized num gives a Wrong Answer (WA).

1 Like

But, it gives the outputs as per the question, so what’s wrong with it.

No, it doesn’t. Try to run it on Compile and run the code with online compiler and IDE | CodeChef , it gives a wrong output. It’s always better to initialize your variables.

1 Like

Thanks, everyone for your advice.