Embercode
✕
C++ OperatorsQuick quiz

Division and modulo

6 questions. Covers Floor division and modulo for negatives.

Questions 1 to 5 of 6

  1. 1. Predict the output of this program. ``cpp #include <iostream> using namespace std; int main() { cout << -7 / 2 << ' ' << 7 / -2 << ' ' << -7 % 3 << endl; return 0; } ``
  2. 2. Predict the output of this program. ``cpp #include <iostream> using namespace std; int main() { cout << -10 % 4 << ' ' << 10 % -4 << ' ' << -10 / 4 << endl; return 0; } ``
  3. 3. Predict the output of this program. ``cpp #include <cmath> #include <iostream> using namespace std; int main() { cout << floor(-9 / 4) << ' ' << floor(-9 / 4.0) << endl; return 0; } ``
  4. 4. In C++, what does 7 % -2 evaluate to when both operands are int?
  5. 5. What does floor_mod(-1, 5) return, using the helper from this lesson?

5 question(s) left on this page.