Mod of Negative Numbers
This may not b a new question to most of you but since am a newbie, please consider answering this.
For languages like c/c++ and java, how does mod % operator work with negative numbers.
for e.g and trying to fetch the output of -3%2 . The actual output is -1 whereas it should be just one.
Could you help me to come out with a solution on how shall I generate the correct output for negative numbers.
Re: Mod of Negative Numbers
Visual C++ 2008 test code:
If you think it should be 1, does that mean you think the division should return -2? If you subtract X from -3 to get +1 then X has to be -4, i.e. -2*2.
|All times are GMT +5.5. The time now is 07:53.|