C primer plus P175 第五题 金字塔

作者在 2020-11-15 15:07:48 发布以下内容
#include <stdio.h>




int main(void)
{

char ch;
bool boo;
do
{
boo=true;
    printf("Input:");
    scanf("%c",&ch);
    if(ch=15) scanf("%c",&ch);
    if(ch<'A' or ch>'Z')
    {
    printf("error! re-input please\n");
    boo=false;
    }
}while(!boo);

int i;
int line=-1;

for(i='A';i<=ch;i++)
{
line++;
for(int j=0;j<=ch-i;j++)
{
printf(" ");
}

for(int j=0;j<=line;j++)
{
printf("%c",j+'A');
}

for(int j=line-1;j>=0;j--)
{
printf("%c",j+'A');
}
for(int j=0;j<=ch-i;j++)
{
printf(" ");
}

printf("\n");
}
    
    

return 0;
}





练习题 | 阅读 1211 次
文章评论,共0条
游客请输入验证码
浏览34839次