c语言编程练习题:7-123 空心字母金字塔
作者:yunjinqi   类别:    日期:2023-05-31 16:40:02    阅读:445 次   消耗积分:0 分    

image.png

#include <stdio.h>
int main(){
    char alpha_arr[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    char c;
    char alpha;
    // int count=0;
    if (scanf("%c",&c)!=EOF){
        for (int i=0;i<26;i++){
            alpha = alpha_arr[i];
            // printf("%c %c\n",alpha,c);
            if (alpha<c){
                if (i==0){
                    // 打印39个空格
                    for (int j=0;j<39-i;j++){
                        printf("%c",' ');
                    }
                    printf("%c\n",alpha);
                }else{
                    // 打印开始的空格
                    for (int j=0;j<39-i;j++){
                        printf("%c",' ');
                    }
                    // 打印字母
                    printf("%c",alpha);
                    // 打印中间空格
                    for (int j=0;j<2*i-1;j++){
                        printf("%c",' ');
                    }
                    // 打印字母
                    printf("%c\n",alpha);
                }
                
            }
            if (alpha==c){
                for (int j=0;j<39-i;j++){
                        printf("%c",' ');
                    }
                for (int j=0;j<2*i+1;j++){
                        printf("%c",alpha);
                    }
            }
        }
    }
    else{
        printf("input wrong");
    }
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/248
上一篇:c语言编程练习题:7-122 3n 1
下一篇:c语言编程练习题:7-124 上三角数字三角形