0
点赞
收藏
分享

微信扫一扫

C语言 金字塔

他说Python 2022-01-24 阅读 124
c语言

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;
}
举报

相关推荐

0 条评论