So, having big time meltdown about the math behind modulo calculations.
The examples state that 23 % 10 = 3. I get that, because 23 / 10 = 2,3 where the remainder is 3. No worries there. BUT further examples looks like this:
17 % 5 = 2
13 % 7 = 6
In my book 17 / 5 = 3,4 and the remainder should be 4, not 2.
And 13 / 7 = 1,857[…] and the remainder should be 8 (or maybe 9 if you round up) but not 6!
What am I doing wrong?
you understand it wrong, lets look at this example:
17 % 5 = 2
what is the biggest number divisible by 5 which is less then 17? it is 15, so then you have 17 - 15 which means you have a remainder of two
Oh! Thanks, but what about 13? It’s not dividable by anything except 13 and 1.
you mean this one:
13 % 7 = 6
?
doesn’t matter? You divide 13 by 7, the biggest division you can make is 7 (14 is not possible) so then you have 13 - 7 = 6 remaining
the modulo gives you the remainder (what can’t be divided by the number you are dividing with)
1 Like