Embercode
✕
C++ PatternsQuick quiz

Rows and mirrors

7 questions. Covers Mirror symmetry.

Questions 1 to 5 of 7

  1. 1. What does this program print? ``cpp #include <iostream> #include <string> int main() { const int n = 3; for (int i = 0; i < n; ++i) { std::string half(i + 1, '*'); std::string gap(2 * (n - 1 - i), ' '); std::cout << half << gap << half << '\n'; } } ``
  2. 2. What does this program print? ``cpp #include <iostream> #include <string> int main() { const int rows = 3; for (int row = 1; row <= rows; ++row) { std::string line(rows - row, ' '); line += std::string(2 * row - 1, '*'); std::cout << line << '\n'; } } ``
  3. 3. This program is meant to print a stack of rows, but it crashes on the last step. What is the bug? ``cpp #include <iostream> #include <string> int main() { const int n = 4; for (int i = 0; i <= n; ++i) { std::cout << std::string(2 * (n - 1 - i), ' ') << std::string(i + 1, '*') << '\n'; } } ``
  4. 4. This program is meant to print a triangle of stars: one star on row 1, two on row 2 and three on row 3. What is the bug? ``cpp #include <iostream> #include <string> int main() { const int rows = 3; std::string line; for (int row = 1; row <= rows; ++row) { for (int col = 1; col <= row; ++col) { line += '*'; } std::cout << line << '\n'; } } ``
  5. 5. True or false: a number pyramid's right half can be made by printing the left half again, the same way the star mirror is made.

5 question(s) left on this page.