C++ Online Compiler
Example: C++ Program to Draw Rectangle using For loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Draw Rectangle using For loop #include <iostream> using namespace std; int main() { int r = 0, c = 0, i, j; // r - denotes the number of rows // c - denotes the number of columns cout << "-----Enter the number of rows & columns-----\n"; cin >> r >> c; for (i = 1; i <= r; i++) { for (j = 1; j <= c; j++) { if (i == 1 || i == r || j == 1 || j == c) cout << "* "; else cout << " "; } cout << "\n"; } return 0; }
8 12
Output
Clear
ADVERTISEMENTS