1. homework 1b (12.09) - Syerikgul/Homeworks GitHub Wiki
#include
int main() { int n; do { std::cout << "Input n (n>0): "; std::cin >> n; } while (n <= 0);
char background = ' ', foregraound = ' ';
int step;
// Верхний треугольник
for (int i = 1; i <= n; ++i) {
for (step = 1; step <= n; ++step) {
for (int j = 1; j <= n - i; ++j) {
std::cout << " ";
}
for (int j = 1; j <= 2 * i - 1; ++j) {
std::cout << "*";
}
for (int j = 1; j <= n - i; ++j) {
std::cout << " ";
}
}
std::cout << std::endl;
}
// Нижний треугольник
for (int i = n - 1; i >= 1; --i) {
for (int step = 1; step <= n; ++step) {
for (int j = 1; j <= n - i; ++j) {
std::cout << " ";
}
for (int j = 1; j <= 2 * i - 1; ++j) {
std::cout << "*";
}
for (int j = 1; j <= n - i; ++j) {
std::cout << " ";
}
}
std::cout << std::endl;
}
}