0

Question about % operator

% operator returns remainder of value on left divided by the value on right. So 10%6 == 4. But what happens when the value on left side is smaller than what is on right side? So 6%10 == 6 and 3 % 20 == 3 but why, how? If you divide 6 by 10 the answer will be 0.6 and there will be NO REMAINDER then why 6%10 is 6? Why if left value is smaller than right value returns the left value as it is?

2nd Jun 2022, 2:57 PM
RD Singh
2 Respuestas
+ 2
RD Singh Remainder is the value left after the division. If a number (dividend) is not completely divisible by another number (divisor) then we are left with a value once the division is done. This value is called the remainder. For example, 10 is not exactly divided by 3. 3 * 3 + 1 = 10 so here reminder would be 1 3 % 30 means 30 * 0 = 0 + 3 so reminder is 3 10 % 6 means 6 * 1 = 6 + 4 so reminder is 4 6 % 10 means 10 * 0 = 0 + 6 so reminder is 6
2nd Jun 2022, 5:05 PM
A͢J
A͢J - avatar
+ 3
Because it does integer division. What are the result and remainder of the integer division of 6 by 10?
2nd Jun 2022, 3:04 PM
Emerson Prado
Emerson Prado - avatar