#include <stdio.h> #include <string.h> #define MAXN 10 int a[MAXN][MAXN]; int main(){ #ifdef LOCAL freopen("ar.in","r",stdin); freopen("ar.out","w",stdout); #endif int n,first,i,j,x,y; while(scanf("%d",&n)==1){ memset(a,0,sizeof(a)); a[x=0][y=n-1] = first = 1; while(first<n*n){ while(x+1<n&&!a[x+1][y]){a[++x][y]=++first;} while(y-1>=0&&!a[x][y-1]){a[x][--y]=++first;} while(x-1>=0&&!a[x-1][y]){a[--x][y]=++first;} while(y+1<n&&!a[x][y+1]){a[x][++y]=++first;} } for(i = 0; i < n; i++){ for(j = 0; j < n; j++){ printf("%3d",a[i][j]); } printf("/n"); } } return 0; } 没有什么思想!