http://ybt.ssoier.cn:8088/problem_show.php?pid=2027
【题目描述】
对于给定的自然数n(n<20),在屏幕上输出仅由“*
”构成的n行的直角三角形。
【输入】
输入n。
【输出】
题述三角形。
【输入样例】
5
【输出样例】
*
**
***
****
*****
正文
本题很水,不必多说。上代码!
#include<iostream>
using namespace std;
int a;
int main() {
cin >> a;
for (int i = 1; i <= a; i++) {
for (int j = 1; j <= i; j++)
cout << '*';
cout << '\n';
}
return 0;
}
压缩一下:
#include<iostream>
using namespace std;
int main() {
int a;cin >> a;for (int i = 1; i <= a; i++) {for (int j = 1; j <= i; j++){cout << '*';}cout<< '\n';}return 0;}
😎😎