#include <stdio.h>#define N 10 void main(){ int M[N][N]={0}; int k=1,n; printf("Please Enter n:"); scanf("%d",&n); int i=0,j=0; int direction=1; int edge1=n-1, edge2=n-1,edge3=0, edge4=1; while(k<=n*n) { M[i][j]=k; switch(direction) { case 1: j++; if(j>=edge1){edge1--;direction=2;} break; case 2: i++; if(i>=edge2){edge2--;direction=3;} break; case 3: j--; if(j<=edge3){edge3++;direction=4;} break; case 4: i--; if(i<=edge4){edge4++;direction=1;} break; } k++; } ////////////////////////////////////////////////// for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%3d",M[i][j]); } printf("\n"); }}