ZSTUOJ平台刷题③:Problem A.--打印金字塔

Problem A: 打印金字塔

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 10011  Solved: 6227

Description

请编写程序输出金字塔图形。

Input

输入一个正整数n。

Output

输出n层的金字塔。

Sample Input

1
3
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;
        }
    }
    
    return 0;
}

 

posted @ 2021-05-17 16:39  Ta7KiXuoul  阅读(149)  评论(0编辑  收藏  举报