#include <iostream> using namespace std; int const arsize = 11; void main() { int num, garo=0, sero=0, cnt=1; cout << " 원하는 마방진의 크기를 입력하세요 (11 이하의 홀수만) : "; cin >> num; int square[arsize][arsize]={0,}; sero = num/2; square[0][sero]=1; while ( cnt < num*num ) { garo--; sero++; if (garo < 0) garo = num-1; if (sero > num-1) sero = 0; if (square[garo][sero] !=0) { garo+=2, sero-=1;} if (garo > num-1) garo = 1; if (sero < 0) sero = num-1; square[garo][sero]=++cnt; } for (int i = 0 ; i <num; i++) { for ( int j = 0 ; j < num ; j++) { cout << square[i][j] << "\t"; } cout << endl; } }