Negative Modulo in C++
Level 125 keystrokes
Prints the remainder of -7 divided by 3, which is -1 in C++.
C++ code
// Integer division truncates toward zero, so -7 / 3 is -2// The remainder therefore takes the sign of -7: -7 = 3 * (-2) + (-1), giving -11cout << (-7 % 3) << endl;Output
-1
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-× 1;× 1(× 1)× 1%× 1