第二题:T2星号三角阵(三)
标签:循环结构
题意:给定一个整数
n
n
n,输出一个
n
n
n行
n
n
n列的星号三角阵,直角位于图形的右上角。(
1
<
=
n
<
=
100
1<=n<=100
1<=n<=100)
例如
n
=
4
n=4
n=4,输出
****
***
**
*
题解:按行数判断输出空格和
∗
*
∗的数量。
代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (j < i) cout << " ";
else cout << "*";
}
cout << endl;
}
return 0;
}