C语言实现:
#includeint chess[8][8]={0}; int a[8],b[15],c[15]; int sum=0;//add all method void PutQueen(int n) { int col,i,j; for(col=0;col<8;col++) { if(a[col]&& b[n+col] && c[n-col+7])//judge a safe place { chess[n][col]=1;//put the queen a[col]=0; b[n+col]=0; c[n-col+7]=0; if(n==7) { sum++; printf("No.%d:\n",sum);//Output queen pendulum method for(i=0;i<8;i++){ printf("\t"); for(j=0;j<8;j++) printf("%d ",chess[i][j]); printf("\n"); } printf("\n"); if(sum%5==0)//Each output 10 kinds of suspension { printf("Press Enter To Continue……"); getchar(); } } else PutQueen(n+1);//recursion function chess[n][col]=0;//Cancel the queen b[n+col]=1; c[n-col+7]=1; a[col]=1; } } } void main() { int i; for(i=0;i<8;++i) a[i]=1; for(i=0;i<15;++i) { b[i]=1; c[i]=1; } PutQueen(0); printf("The total number of eight queen pendulum method: %d\n",sum); }