C语言,再次请教一下,真不知道为啥编译出来的都是错的,求dl教
查看原帖
C语言,再次请教一下,真不知道为啥编译出来的都是错的,求dl教
593001
Langrange2021楼主2022/7/29 17:45
#include <stdio.h>
int main()
{
    int N;
    int square[40][40];
    int x = 1;
    int i;
    scanf("%d", &N);
    int y = (N + 1) / 2;
    square[x][y] = 1;
    for (i = 2; i <= N * N; i++)
    {
        if (x == 1 && y != N)
        {
            square[N][y + 1] = i;
            x = N;
            y += 1;
            continue;
        }
        else if (y == N && x != 1)
        {
            square[x - 1][1] = i;
            x -= 1;
            y = 1;
            continue;
        }
        else if(x==1&&y==N)
        {
            square[x + 1][y] = i;
            x += 1;
            continue;
        }
        else if (x != 1 && y != N)
        {
            square[x - 1][y + 1] = i;
            x -= 1;
            y += 1;         
            continue;
        }
        else
        {
            square[x + 1][y] = i;
            x += 1;
            continue;
        }
    }
    for (int m = 1; m <= N; m++)
    {
        for (int k = 1; k <= N; k++)
        {
            printf(" %d ", square[m][k]);
        }
        printf("\n");
    }
    return 0;
}
2022/7/29 17:45
加载中...