acwing756蛇形矩阵C语言
时间: 2023-12-03 22:38:57 浏览: 117
以下是acwing756蛇形矩阵的C语言代码实现:
```c
#include <stdio.h>
const int N = 110;
int n, m;
int a[N][N];
int main()
{
scanf("%d%d", &n, &m);
int x = 1, y = 1, tot = 0;
while (tot < n * m)
{
while (y <= m && !a[x][y]) a[x][y++] = ++tot;
y--, x++;
while (x <= n && !a[x][y]) a[x++][y] = ++tot;
x--, y--;
while (y >= 1 && !a[x][y]) a[x][y--] = ++tot;
y++, x--;
while (x >= 1 && !a[x][y]) a[x--][y] = ++tot;
x++, y++;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
printf("%d%c", a[i][j], j == m ? '\n' : ' ');
return 0;
}
```
阅读全文
相关推荐













