1#include <stdio.h>
2#include <stdlib.h>
3
4int main(int c, char **v)
5{
6 int i, j, m, n, *s;
7
8 /* default size: 5 */
9 if (c < 2 || ((m = atoi(v[1]))) <= 0) m = 5;
10
11 /* alloc array*/
12 s = malloc(sizeof(int) * m * m);
13
14 for (i = n = 0; i < m * 2; i++)
15 for (j = (i < m) ? 0 : i-m+1; j <= i && j < m; j++)
16 s[(i&1)? j*(m-1)+i : (i-j)*m+j ] = n++;
17
18 for (i = 0; i < m * m; putchar((++i % m) ? ' ':'\n'))
19 printf("%3d", s[i]);
20
21 /* free(s) */
22 return 0;
23}