What is modulo operation?
When we divide two integers
a and
b, we write
a
b
= q (r),
where
a is the dividend,
b is the divisor,
q is the quotient, and
r is the remainder.
Sometimes, we only want to find what the remainder is when we divide two numbers. For these cases, there is an operator called the ”modulo operator” (abbreviated as ”mod”).
Therefore, from the above equation, we have
a mod b = r,
i.e.
a modulo
b is equal to
r, where
b is referred to as the modulus. The word ”modulo” comes from a Latin word ”modus” meaning a measure. When we use the word modulo, we mean the modulo operation, or simply finding the remainder.
Many programming languages, and calculators, have a mod operator, represented with the % symbol. If we calculate the result of a negative number, some languages will give us a negative result.