~cpp //마방진 #include<iostream.h> int main() { int a; int b; int i=0; int j=0; int input; int num=1; do{ cout<<"한자리의 홀수를 입력하시오.\n"; cin>>input; }while(input%2==0 || input>10 || input==0); int mbj[11][11]={{0,},}; a = 1; b = input/2+1; for(i=0;i<11;i++){ mbj[0][i]=85; mbj[10][i]=86; mbj[i][0]=87; mbj[i][10]=88; } mbj[0][0]=89; mbj[a][b]=num; while(num<input*input) { a--; b--; num++; if(mbj[a][b]==85){ if(mbj[input][b]!=0){ a=a+2; b=b+1; } else{ a=input; } mbj[a][b]=num; } else if(mbj[a][b]==89){ if(mbj[input][input]!=0){ a=a+2; b=b+1; } else{ a=input; b=input;} mbj[a][b]=num; } else if(mbj[a][b]==87){ if(mbj[a][input]!=0){ a=a+2; b=b+1; } else b=input; mbj[a][b]=num;} else if(mbj[a][b]==0) mbj[a][b]=num; else{ a=a+2; b=b+1; mbj[a][b]=num;} } for(i=1;i<input+1;i++){ for(j=1;j<input+1;j++) cout<<mbj[i][j]<<"\t"; cout<<"\n"; } return 0; }