C++ Online Compiler
Example: Box Outline in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Box Outline #include <iostream> using namespace std; int main() { int width, height; // Step 1: Get dimensions from the user cout << "Enter the width of the box: "; cin >> width; cout << "Enter the height of the box: "; cin >> height; // Step 2: Iterate through each row for (int i = 1; i <= height; ++i) { // Step 3: Iterate through each column in the current row for (int j = 1; j <= width; ++j) { // Step 4: Check if current position is part of the border if (i == 1 || i == height || j == 1 || j == width) { cout << "*"; // Print asterisk for border } else { cout << " "; // Print space for interior } } cout << endl; // Move to the next line after each row } return 0; }
Output
Clear
ADVERTISEMENTS