How does modulus of a smaller dividend and larger divisor work?

后端 未结 10 1288
误落风尘
误落风尘 2020-12-15 04:47
7 % 3 = 1 (remainder 1)

how does
3 % 7 (remainder ?)

work?

10条回答
  •  半阙折子戏
    2020-12-15 05:23

    Conceptually, I think of it this way. By definition, your dividend must be equal to (quotient * divisor) + modulus

    Or, solving for modulus: modulus = dividend - (quotient * divisor)

    Whenever the dividend is less than the divisor, the quotient is always zero which results in the modulus simply being equal to the dividend.

    To illustrate with OP's values:

    modulus of 3 and 7 = 3 - (0 * 7) = 3
    

    To illustrate with other values:

    1 % 3:
    1 - (0 * 3) = 1
    
    2 % 3:
    2 - (0 * 3) = 2
    

提交回复
热议问题