1 int matrix[MAX][MAX]; 2 void PrintMatrix(int x,int y,int start,int n) 3 { 4 if(n==0) 5 return ; 6 if(n==1) 7 { 8 matrix[x][y] = start; 9 return ; 10 } 11 int i,j; 12 for(j=y;j<y+n-1;j++) 13 matrix[x][j] = start++; 14 for(i=x;i<x+n-1;i++) 15 matrix[i][y+n-1] = start++; 16 for(j=y+n-1;j>y;j--) 17 matrix[x+n-1][j] = start++; 18 for(i=x+n-1;i>x;i--) 19 matrix[i][y] = start++; 20 PrintMatrix(x+1,y+1,start,n-2); 21 }