getting wa even though I am pretty sure it is correct

Try 5 2 … you are wrong there…

See the test case : zVcFly - Online C++0x Compiler & Debugging Tool - Ideone.com

I think it is giving the right output.
Please tell me how you consider it wrong

thanks a lot.Can’t believe I was neglecting such an obvious case

welcome :slight_smile: