Math Fundamentals18 sections · 814 units
Open in Course

The Mod Operator

(Remainder after division)

For any integers a and m where m > 0, a mod m gives the remainder when you divide a by m. The result is always between 0 and m - 1.

Examples: 17 mod 5 = 2 because 17 = 3 × 5 + 2. Also 23 mod 7 = 2 because 23 = 3 × 7 + 2. And 100 mod 10 = 0 because 100 divides evenly by 10.

In code, most languages use the % operator: 17 % 5 gives 2.