How Does Modulus Divison Work

后端 未结 19 1556
栀梦
栀梦 2020-11-22 06:55

I don\'t really understand how modulus division works. I was calculating 27 % 16 and wound up with 11 and I don\'t understand why.

I can\'t

19条回答
  •  情歌与酒
    2020-11-22 07:09

    The modulus operator takes a division statement and returns whatever is left over from that calculation, the "remaining" data, so to speak, such as 13 / 5 = 2. Which means, there is 3 left over, or remaining from that calculation. Why? because 2 * 5 = 10. Thus, 13 - 10 = 3.

    The modulus operator does all that calculation for you, 13 % 5 = 3.

提交回复
热议问题