C/C++编程学习 - 第22周 ⑨ 图形输出1

题目链接

题目描述

输入一个n,输出n层图形,见下(图为n=4的情况):

*
**
***
****

Input
输入一个数n

Output
输出相应的图形

Sample Input

6

Sample Output

*
**
***
****
*****
******

思路

输入一个数n,输出n行的图形,每1行有1个*,第二行有2个*,……第n行有n个*。

C++代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int n;
	while(cin >> n)
	{
    
    
		for(int i = 1; i <= n; i++)
		{
    
    
			for(int j = 1; j <= i; j++)
				cout << "*";
			cout << endl;
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44826711/article/details/113572777