题解 | #牛牛的字符菱形#

牛牛的字符菱形

https://www.nowcoder.com/practice/11a5040fa894430f9d25fda1be37ddc8

#include<stdio.h>
int main() {
    char ch;
    int i = 0, a = 0, b = 0;
    scanf("%c", &ch);
    for (i = 1; i < 10; i++) {
        if (i % 2 == 1 && i < 6) {
            for (b = 0; b < (5 - i) / 2; b++) {
                printf(" ");
            }
            for (a = 0; a < i; a++) {
                printf("%c", ch);
            }
            for (b = 0; b < (5 - i) / 2; b++) {
                printf(" ");
            }
            printf("\n");
            b = 0;
        } else if (i % 2 == 1 && i >= 6) {
            for (b = 0; b < (i - 5) / 2; b++) {
                printf(" ");
            }
            for (a = 0; a < 10 - i; a++) {
                printf("%c", ch);
            }
            for (b = 0; b < (i - 5) / 2; b++) {
                printf(" ");
            }
            printf("\n");
            b = 0;
        }
    }
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务