C/C++ Programming Learning-Week 22 ⑨ Graphic output 1

Topic link

Title description

Input an n, output n-layer graphics, see below (the picture shows the case of n=4):

*
**
***
****

Input
input a number n

Output the
corresponding graphics

Sample Input

6

Sample Output

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

Ideas

Input a number n, output n lines of graphics, each line has 1*, the second line has 2*,...the nth line has n*.

C++ code:

#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;
}

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/113572777