ZSTUOJ刷题④:Problem B.--输出双层金字塔

2023-03-10,,

Problem B: 输出双层金字塔

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 7860  Solved: 5834

Description

输出双层金字塔

Input

输入一个大于2的整数

Output

输出n层的双层金字塔

Sample Input

2
5

Sample Output

 *
***
*
*
***
*****
*******
*********
*******
*****
***
*
代码如下:
#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<=n-i;j++){
cout<<" ";
}
for(int k=1;k<=2*i-1;k++){
cout<<"*";
}
cout<<endl;
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=n-i;j++){
cout<<" ";
}
for(int k=1;k<=2*i-1;k++){
cout<<"*";
}
cout<<endl;
}
} return 0;
}

ZSTUOJ刷题④:Problem B.--输出双层金字塔的相关教程结束。

《ZSTUOJ刷题④:Problem B.--输出双层金字塔.doc》

下载本文的Word格式文档,以方便收藏与打印。