题解 | 空心正方形图案

空心正方形图案

https://www.nowcoder.com/practice/72347ee949dc47399186ee183632f303

#include <stdio.h>

int main() {
    int a = 0;
    int i = 0;
    char arr[2] = {'*',' '};
    while (scanf("%d", &a) != EOF) { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to 
        for(i = 0;i < a;i++){
            for(int j = 0;j < a;j++){
                if (i == 0 || i == a - 1) {
                    printf("%c ",arr[0]);
                }
                else {
                    if (j == 0 || j == a - 1) {
                        printf("%c ",arr[0]);
                    }
                    else {
                        printf("  ");
                    }
                }
            }
            printf("\n");
        }
    }
    return 0;
}

全部评论

相关推荐

07-10 13:59
门头沟学院 Java
点赞 评论 收藏
分享
06-05 19:46
已编辑
武汉大学 后端
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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