蓝桥杯 算法训练 ALGO-101 图形显示 循环语句

算法训练 图形显示
时间限制:1.0s 内存限制:512.0MB
问题描述
  编写一个程序,首先输入一个整数,例如5,然后在屏幕上显示如下的图形(5表示行数):
  * * * * *
  * * * *
  * * *
  * *
  *

分析:第一行输出n个星号,第二行输出n-1个星号……
令i从0开始,则第i行,输出n-i个星号。代码如下:

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n - i; j++)
		{
			cout << "* ";
		}
		cout << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43302818/article/details/85090354