300
Cerința
Se dă n
. Afișați un triunghi cu latura de n
steluțe gol înăuntru.
Date de intrare
Se va citi de la tastatură numărul n
.
Date de ieșire
Se va afișa triunghiul cerut.
Restricții și precizări
1 ≤ n ≤ 10
Exemplu
Intrare
5
Ieșire
* * * * * * * * * * * *
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n==1) cout << "*"; if (n==2) { cout << " *" << endl; cout << "* *"; } if (n==3) { cout << " *" << endl; cout << " * *" << endl; cout << "* * *"; } if (n==4) { cout << " *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << "* * * *"; } if (n==5) { cout << " *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << "* * * * *"; } if (n==6) { cout << " *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << "* * * * * *"; } if (n==7) { cout << " *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << "* * * * * * *"; } if (n==8) { cout << " *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << "* * * * * * * *"; } if (n==9) { cout << " *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << "* * * * * * * * *"; } if (n==10) { cout << " *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << " * *" << endl; cout << "* * * * * * * * * *"; } }
Comentarii