Division Assignment in C++

Level 247 keystrokes

Divides x by 2 and then by 5 with /=, so 100 becomes 50 and then 10, and prints 10.

C++ code

// Initializes x with 100
1int x = 100;
// x /= 2 means x = x / 2: 100 / 2 = 50
2x /= 2;
// 50 / 5 = 10; with ints any remainder would be dropped
3x /= 5;
// Prints the final value, 10
4cout << x << endl;

Output

10
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
  • <× 4
  • =× 3
  • /× 2

More C++ examples at level 2

← C++ typing practice