题解 | #空心正方形图案#

知识点:

循环控制:

循环输出图形

#include <iostream>
using namespace std;

int main() {
    int n;

    while (cin >> n) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if ((i == 1) || (i == n) || (j == 1) || (j == n)) {
                    cout << "* ";
                } else {
                    cout << "  ";
                }
            }

            cout << endl;
        }
    }

    return 0;
}

/*
int main() {
    int n;

    while (cin >> n) {
        for (int i = 1; i <= n; i++) {
            if ((i == 1) || (i == n)) {
                for (int j = 1; j <= n; j++) {
                    cout << "* ";
                }
                cout << endl;
            } else {
                for (int j = 1; j <= n; j++) {
                    if ((j == 1) || (j == n)) {
                        cout << "* ";
                    } else {
                        cout << "  ";
                    }
                }
                cout << endl;
            }
        }
    }


    return 0;
}
*/


#算法#
全部评论

相关推荐

牛客34884196...:你期望薪资4-5k,那确实可以重生了,但很难在深圳活下去
点赞 评论 收藏
分享
想按时下班的大菠萝在...:隔壁学校的,加油多投, 实在不好找可以下个学期开学找,把算法八股准备好,项目有空再换换
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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