求助,应该是else那里有问题
查看原帖
求助,应该是else那里有问题
1043489
yiyezhiqiu1011楼主2023/10/20 13:20
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[22][22]={},cnt = 1,y=1,x=n/2+1+1;
    cin >> n;
    a[1][n/2+1] = cnt++;
    while (cnt <= n * n)
    {
        if (--y == 0)
            y = n;
        if (++x > n)
            x = 1;
        if (a[y][x] == 0)a[y][x] = cnt++;
        else
        {
            if (--x == 0)
                x = n;
            a[y][x] == cnt++;
        }
    
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
            cout << a[i][j] << " ";
        cout << endl;
    }
    return 0;
}
2023/10/20 13:20
加载中...