Добавить rectangle.cpp
This commit is contained in:
37
rectangle.cpp
Normal file
37
rectangle.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void drawRectangle(int h, int w, char s = '*') {
|
||||||
|
if (h <= 0 || w <= 0) {
|
||||||
|
cout << "Помилка: висота та ширина повинні бути додатними числами!" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < h; ++i) {
|
||||||
|
for (int j = 0; j < w; ++j) {
|
||||||
|
cout << s;
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
setlocale(0, "");
|
||||||
|
cout << "=== Приклади малювання прямокутників ===" << endl;
|
||||||
|
|
||||||
|
cout << "\nПрямокутник 5x10 зі зірочками (за замовчуванням):" << endl;
|
||||||
|
drawRectangle(5, 10);
|
||||||
|
|
||||||
|
cout << "\nПрямокутник 3x8 з символом '#' :" << endl;
|
||||||
|
drawRectangle(3, 8, '#');
|
||||||
|
|
||||||
|
cout << "\nПрямокутник 4x12 з символом '@' :" << endl;
|
||||||
|
drawRectangle(4, 12, '@');
|
||||||
|
|
||||||
|
cout << "\nПрямокутник 2x6 з символом '+' :" << endl;
|
||||||
|
drawRectangle(2, 6, '+');
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user