C/C++ Arena

Step 3 of 6

Remainder with %

% (modulo) gives the remainder of an integer division.

17 / 5   // 3
17 % 5   // 2   (17 = 3*5 + 2)

It's great for "is this even?" (n % 2 == 0) and for splitting units.

Your turn: a match lasted 754 seconds. Print it as minutes and seconds: 12 min 34 sec.

Previous: The integer division trap Next: Shorthand operators