Why does 3%100 work.

Sep 17, 2019 at 3:33pm
Hello,i do not need help with any code but i came across a problem which contained something along the lines of 3%100 the result of that being 3.I do not know why you can do a one digit number mod a 3 digit one.If someone could help me that would be really helpfull!
Sep 17, 2019 at 3:42pm
a % b is simply the remainder of the integer division a / b.
The remainder is defined as
quotient * divisor + remainder = dividend (where quotient = dividend / divisor)

The quotient of 3 / 100 is 0.
0 * 100 + remainder = 3
remainder = 3

As long as the the divisor is not zero, you can get the remainder of any pair of integers (although note that C++ doesn't specify the result of using negative operands for modulo).
Last edited on Sep 17, 2019 at 3:42pm
Topic archived. No new replies allowed.