0

I can't understand madulo operater plz help me

value=23 res=value%6;

25th Feb 2017, 7:40 AM
dhivya
dhivya - avatar
2 Respostas
+ 4
You need not be afraid of the modulo operator. It is not as complex as you might think. Let's break it down: You are trying to see what is the modulo(remainder) of dividing 23 by 6. Since we know that 6 * 4 is 24, that is over 23. We will need to use the previous multiplication 6 * 3 = 18. The remainder of 23 - 18 = 5. So the answer to 23 % 6 = 5. Just think of modulo in this way, what is the remainder of dividing the number left of the modulo operator by the number right of the modulo operator. In that sense the remainder can only by 0 to the number you are dividing with. In your example, it can be 0, 1, 2, 3, 4 or 5. Hope that clarifies things.
25th Feb 2017, 7:53 AM
Tomer
+ 1
ans 5. modulo operator gives remainder value. 23% 6 remainder is 5. as 3*6+5
25th Feb 2017, 7:50 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar