C++ Online Compiler
Example: Hollow Rectangle Pattern in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Hollow Rectangle Pattern #include <iostream> using namespace std; int main() { int rows = 5; int cols = 6; // Outer loop for rows for (int i = 1; i <= rows; ++i) { // Start from 1 for easier condition checks // Inner loop for columns for (int j = 1; j <= cols; ++j) { // Print '*' for the first row, last row, first column, or last column if (i == 1 || i == rows || j == 1 || j == cols) { cout << "*"; } else { cout << " "; // Print space for the interior } } cout << endl; // Move to the next line after each row } return 0; }
Output
Clear
ADVERTISEMENTS