N=5
13 14 15 16 1
12 23 24 17 2
11 22 25 18 3
10 21 20 19 4
9 8 7 6 5
const int MAXN = 20;
int a[MAXN][MAXN];
int main(int argc, const char * argv[]) {
int n;
cin >>n;
int value, x = 0, y = n-1;
value = a[0][n-1] = 1;
while (value < n*n) {
while (x+1<n && a[x+1][y]==0)
a[++x][y] = ++value;
while (y-1>=0 && a[x][y-1]==0)
a[x][--y] = ++value;
while (x-1>=0 && a[x-1][y]==0)
a[--x][y] = ++value;
while (y+1<n && a[x][y+1]==0)
a[x][++y] = ++value;
}
for (int i=0; i<n; i++) {
for (int j =0; j<n; j++) {
cout <<a[i][j]<<" ";
}
cout <<endl;
}
return 0;
}