字母金字塔

接收用户输入的一个大写字母,如“C”,要求输出如下字母金字塔,其中“_”代表空格:
__A
_ABA
ABCBA

具体要求:
(1)
容许接收多次输入,直到输入为“0 ()”
(2)
如果输入非大写字母,则给出提示,并要求重新输入;

代码:#include <stdlib.h>

int main()
/*输出一个字母金字塔*/
{
    int n=0,m=0,t=0;
    char a='/0',b='/0',c='/0',d='/0';
    printf ("If you want to play this game please input a character./nIf you want end it please input 0./n");

    do
    {
        scanf("%c",&d);
        printf("please input an uppercase :/n");
        scanf(" %c",&a);
        if (a<'A'||a>'Z')
        {
            printf("you input a wrong character/n");
        }
        /*若输入的不是大写字母 则给用户一个提示*/
        else
        {
            m=a-'A'+1;/*计算总共该输出m行*/
            for (n=1;n<=m;n++)
            {
                for (t=0;t<m-n;t++)
                    printf(" ");/*输出每行该有的空格*/
                for (b='A';b<='A'+n-1;b++)
                    printf("%c",b);/*正序输出字母*/
                for (c='A'+n-2;c>='A';c--)
                    printf("%c",c);/*逆序输出字母*/
                printf("/n");
            }
            printf("If you want end please input 0,or input anther character/n");
            scanf(" %c",&d);
        }
    }while (d!='0');/*当d==0时结束循环*/
    printf("The end!");
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值