Description
输入一个正整数n,生成一个层数为n的金字塔。详细图形请看样例。注意n=1时,就没有地板了。
Input
第一行一个整数n(1≤n≤100),表示层数。
Output
输出n层金字塔,注意金字塔是完全对称的,在金字塔的右侧也需要输出与左侧相同的空格。
Sample Input 1
Sample Output 1
Code
#include<stdio.h>
void kong(int n)
{
for(int i=1; i<n; i++)
printf(" ");
}
void xia(int n)
{
for(int i=0; i<n; i++)
printf("_");
}
int main(void)
{
int n,temp,count=0;
scanf("%d",
temp=n;
for(int i=0; i<n; i++)
{
kong(temp);
printf("/");
xia(2*count);
printf("\\");
kong(temp);
temp--;
count++;
printf("\n");
}
return 0;
}