奇数幻方: 方法描述:http://zh.wikipedia.org/wiki/幻方 #include <stdio.h> #define DIMENSION 7 //阶数 void main(){ int Array[DIMENSION][DIMENSION]={0}; int m=0,n=DIMENSION/2; int total=DIMENSION*DIMENSION,count=1; do{ Array[m][n]=count; m=(m-1+DIMENSION)%DIMENSION; n=(n+1+DIMENSION)%DIMENSION; if(Array[m][n]) {m=(m+2+DIMENSION)%DIMENSION;n=(n-1+DIMENSION)%DIMENSION;} }while(count++<total); for(m=0;m<DIMENSION;m++){ for(n=0;n<DIMENSION;n++) printf("%-3.d ",Array[m][n]); printf("/n"); }//for }