Submit
Statistic
Discuss
Problem Description
输入n值,打印下列形状的金字塔,其中n代表金字塔的层数。
Input
输入只有一个正整数n。
Output
打印金字塔图形,其中每个数字之间有一个空格。
Sample Input
3
Sample Output
1
1 2 1
1 2 3 2 1
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,i,j,t;
cin >> a;
for(i=1; i<=a; i++)
{
t=2*(a-i);
while(t--)
{
cout << " ";
}
if(i==1)
{
cout << 1;
}
else
{
for(j=1; j<=i; j++)
{
cout << j << " ";
}
for(j=i-1; j>=1; j--)
{
if(j==1)
{
cout << j;
}
else
{
cout << j << " ";
}
}
}
cout << endl;
}
return 0;
}