include[HTML_REMOVED]
int main()
{
int N, M;
scanf(“%d %d”, &N, &M);
int a = N, b = M;
int arr[N][M] = { 0 };
int n = 0, m = 0;
int count = 1;
//前面这一段的问题怎么改啊?用ai搜这一块也有问题,大概也是N,M是常变量的问题,这个问题vs一直有
while (N != 0 && M != 0)//这里是想循环→↓←,感觉好像还行
{
//1
if (M == 1)
{
for (int i = 0; i < N ; i)
{
arr[n][m] = count;
n;
}
M–;
}
else
{
for (int i = 0; i < M - 1; i)
{
arr[n][m] = count;
m;
count;
}
N–;
}
//2
if (N == 1)
{
for (int i = 0; i < N; i++)
{
arr[n][m] = count++;
m++;
}
N--;
}
else
{
for (int i = 0; i < N -1; i++)
{
arr[n][m] = count;
n++;
count++;
}
M--;
}
//3
if (M == 1)
{
for (int i = 0; i < N; i++)
{
arr[n][m] = count++;
m--;
}
M--;
}
else
{
for (int i = 0; i < M - 1; i++)
{
arr[n][m] = count;
count++;
m--;
}
N--;
}
//4
for (int i = 0; i < N - 1; i++)
{
arr[n][m] = count;
count++;
n--;
}
M--;
}
for (int i = 0; i < a; i++)
{
for (int u = 0; u < b; u++)
{
printf("%d ", arr[i][u]);
if (u == b - 1)
printf("\n");
}
}
return 0;
}