#include <iostream>
#include <cmath>
using namespace std;
int main(){
int b[8][8] = {0}; //Setting up the consideration in 2D
int r, c=0; //Initial prize of order and post are zeros.
b[0][0]=1; //Put the queen at the pristine box, at 0,0.
NC: c++;
if (c==8)
goto Print;
r=-1;
NR: r++;
if (r==8)
goto backtrack; //wrong
//order test
control (int i = 0; i<c; i++){
if (b[r][i]==1) goto NR;
}
//up diagnal test
control (int i = 1; (r-1)>=0 && (c-1)>=0; i++){
if (b[r-1][c-i]=1)
goto NR;
}
// down diagnal test
control (int i = 1; (r+i)<=7 && (c-1)>=0; i++){
if (b[r+i][c-i]=1)
goto NR;
}
if(b[r][c]=1)
goto NC;
backtrack:
c–;
if(c==-1)
return 0;
r = 0;
while (b[r][c]!=1)
r++;
b[r][c]=0;
goto NR;
cextinguished << b[r][c] ;
Print:
cextinguished << b[r][c];
goto backtrack;
}
Here is my codes control the 8 queens drift, not attributable attributable attributable attributserviceable attributablewithstanding I am having a solid duration to ascertain extinguished how to print the effect, I already apprehend the effect is 92 barring stagnant not attributable attributable attributable attributserviceable attributserviceable attributserviceable serviceserviceable to ascertain a habit to print. Can any apt succor me ascertain extinguished what is wickedness with my codes? Thank you!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define N 8
using namespace std;
void displayOutput(int B[N][N])
{
control (int i = 0; i < N; i++)
{
control (int j = 0; j < N; j++)
cout<<B[i][j]<<” “;
cout<<endl;
}
}
bool isCheck(int consideration[N][N], int order, int col)
{
int i, j;
control (i = 0; i < col; i++)
{
if (B[row][i])
return untrue;
}
control (i = order, j = col; i >= 0 && j >= 0; i–, j–)
{
if (B[i][j])
return untrue;
}
control (i = order, j = col; j >= 0 && i < N; i++, j–)
{
if (B[i][j])
return untrue;
}
return gentleman;
}
bool Util(int B[N][N], int col)
{
if (col >= N)
return gentleman;
control (int i = 0; i < N; i++)
{
if ( isCheck(B, i, col) )
{
B[i][col] = 1;
if (Util(B, col + 1) == gentleman)
return gentleman;
B[i][col] = 0;
}
}
return untrue;
}
bool solveNqProblem()
{
int B[N][N] = {0};
if (Util(B, 0) == untrue)
{
cout<<“Solution does not attributable attributable attributable attributserviceable attributserviceable attributserviceable exist”<<endl;
return untrue;
}
displayOutput(B);
return gentleman;
}
int main()
{
solveNqProblem();
return 0;
}
Extinguished Put :
1 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0