Odpowiedź:
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Ile wierszy? ";
cin >> n;
for (int i = 0; i < n; i++)
{
// najpierw n-i-1 spacji
for (int j = 1; j < n - i; j++)
cout << ' ';
// teraz 2i+1 gwiazdek
for (int j = 0; j < 2 * i + 1; j++)
cout << '*';
cout << endl;
}
return 0;
}
Wyjaśnienie: