Modulo Assignment in C++

Level 238 keystrokes

Replaces x with the remainder of 17 divided by 5 using %=, and prints 2.

C++ code

// Initializes x with 17
1int x = 17;
// x %= 5 means x = x % 5; 17 = 5 * 3 + 2, so x becomes 2
2x %= 5;
// Prints the remainder, 2
3cout << x << endl;

Output

2
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C++ code and how often they appear.

  • <× 4
  • ;× 3
  • =× 2
  • %× 1

More C++ examples at level 2

← C++ typing practice