I'm messing with the modulo operation in python and I understand that it will spit back what the remainder is.
But what if the first number is smaller than the second?
for instance
2 % 5 the answer is 2.
How does that work?
2/5 = .4
If the numerator is smaller than the denominator, then the remainder is equal to the numerator. 3 % 10 =3 //If smaller number i.e. 3 is divided by bigger number i.e. 10, then the numerator becomes the remainder.
The range of values for an integer modulo operation of n is 0 to n − 1 inclusive (a mod 1 is always 0; a mod 0 is undefined, possibly resulting in a division by zero error in some programming languages). See Modular arithmetic for an older and related convention applied in number theory.
Answer. No, the result of a modulo operation can never be larger than the divisor, assuming all positive values being used in the operation. If the division is done correctly, then the divisor was fitted into the dividend as many times as possible.
Most programming languages adopt the convention that the modulo operator (denoted by % rather than mod ) occupies the same place in the order of operations as multiplication and division. Hence, it comes AFTER the operations in parentheses, but BEFORE addition and subtraction.
Does this help
22 % 5 = 2 17 % 5 = 2 12 % 5 = 2 7 % 5 = 2 2 % 5 = 2
Maybe this
22 / 5 = 4 + 2/5 17 / 5 = 3 + 2/5 12 / 5 = 2 + 2/5 7 / 5 = 1 + 2/5 2 / 5 = 0 + 2/5
5 goes into 2 zero times.
5*0 = 0
2-0 = 2.
The answer is 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With