C语言实验——打印金字塔
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
输入n值,打印下列形状的金字塔,其中n代表金字塔的层数。


Input
输入只有一个正整数n。
Output
打印金字塔图形,其中每个数字之间有一个空格。
Example Input
3
Example Output
1 1 2 1 1 2 3 2 1
Hint
Author
参考代码
#include<stdio.h>
int main()
{
int n;
int i;
int c;
int temp;
scanf("%d",&n);
for(i = 1; i <= n; i++)
{
for(temp = i; temp < n; temp++)
{
printf(" ");
}
for(c = 1; c <= i; c++)
{
if(i == 1)
{
printf("%d",c);
}
else
printf("%d ",c);
}
for(c = i - 1; c > 0; c--)
{
if(c == 1)
{
printf("%d",c);
}
else
printf("%d ",c);
}
printf("\n");
}
return 0;
}