c++输出上下金字塔

时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format:%lld

题目描述

输出双层金字塔。

输入描述:

多个测试数据。每个测试数据输入一个整数n( 2 <= n <= 9)

输出描述:

输出双层金字塔
链接:https://ac.nowcoder.com/acm/problem/22204
来源:牛客网

示例1

输入

> 2
> 5

输出



*
***
 *
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n-i;j++)
		{
			cout<<" ";
		}
		for(int j=1;j<=2*i-1;j++)
		{
			cout<<"*";
		}
		cout<<endl;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=n-1;j>=n-i;j--)
		{
			cout<<" ";
		}
		for(int j=2*(n-1)-1;j>=2*i-1;j--)
		{
			cout<<"*";
		}
		cout<<endl;
	}
}
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章