Question #89945

Write a C++ Program to draw 2 rectangles and fill One of them.

Expert's answer

#include <iostream>
using namespace std;


int main() {
  // 1st rectangle
  for (int i = 0; i < 5; ++i) {
    for (int j = 0; j < 10; ++j) {
      if (
        i == 0 || i == 4 ||
        j == 0 || j == 9
      ) {
        cout << "*";
      } else {
        cout << " ";
      }
    }
    cout << endl;
  }


  cout << endl;


  // 2nd rectangle (filled)
  for (int i = 0; i < 5; ++i) {
    for (int j = 0; j < 10; ++j) {
      cout << "*";
    }
    cout << endl;
  }
}

LATEST TUTORIALS
APPROVED BY CLIENTS