# Include <iostream> using namespace STD; const int M = 4; const int N = 4; int mat [m] [N]; bool vis [m] [N]; int dir = 1; void Init () {memset (VIS, 0, sizeof (VIS); int num = 1; for (INT I = 0; I <m; I ++) for (Int J = 0; j <n; j ++) mat [I] [J] = num ++;} int main () {Init (); int I = 0, j =-1, Count = 0; while (count <m * n) {If (DIR = 1) {While (! Vis [I] [J + 1] & J + 1 <n) {cout <mat [I] [J + 1] <""; vis [I] [J + 1] = 1; count ++; j ++;} dir = 2;} If (DIR = 2) {While (! Vis [I + 1] [J] & I + 1 <m) {cout <mat [I + 1] [J] <""; vis [I + 1] [J] = 1; count ++; I ++;} dir = 3;} If (DIR = 3) {While (! Vis [I] [J-1] & J-1> = 0) {cout <mat [I] [J-1] <""; vis [I] [J-1] = 1; count ++; j --;} dir = 4;} If (DIR = 4) {While (! Vis [I-1] [J] & I-1> = 0) {cout <mat [I-1] [J] <"; vis [I-1] [J] = 1; count ++; I --;} dir = 1 ;}} system ("pause"); Return 0 ;}