>>333
#include <stdio.h>
#include <math.h>
#define WIDTH 5
#define HEIGHT 5
int i, j, k, y, x, dir, max_digit, digit;
int num[HEIGHT][WIDTH];
int main(void) {
    if(WIDTH <= 0 || HEIGHT <= 0) { return; }
    for (i = 0; i < HEIGHT; i++) { for (j = 0; j < WIDTH; j++) { num[i][j] = 0; } }
    y = x = dir = 0;
    for (i = 1; ; i++) {
        num[y][x] = i;
        switch (dir) {
            case 0: { x++; if (WIDTH <= x || num[y][x] != 0) { x--; dir = 1; y++; } break; }
            case 1: { y++; if (HEIGHT <= y || num[y][x] != 0) { y--; dir = 2; x--; } break; }
            case 2: { x--; if (x < 0 || num[y][x] != 0) { x++; dir = 3; y--; } break; }
            case 3: { y--; if (y < 0 || num[y][x] != 0) { y++; dir = 0; x++; } break; }
        }
        if (x < 0 || WIDTH <= x || y < 0 || HEIGHT <= y || num[y][x] != 0) { break; }
    }
    max_digit = (int)log10(WIDTH * HEIGHT);
    for (i = 0; i < HEIGHT; i++) {
        for (j = 0; j < WIDTH; j++) {
            digit = (int)log10(num[i][j]);
            for(k = 0; k < max_digit - digit + 1; k++) { putchar(' '); }
            printf("%d", num[i][j]);
        }
        putchar('\n');
    }
}