Question: #include #include using namespace std; int main(){ int b[8][8] = {0}; //Setting up the board in 2D int r, c=0; //Initial value of row and
#include
#include
using namespace std;
int main(){
int b[8][8] = {0}; //Setting up the board in 2D
int r, c=0; //Initial value of row and column are zeros.
b[0][0]=1; //Put the queen at the first box, at 0,0.
NC: c++;
if (c==8)
goto Print;
r=-1;
NR: r++;
if (r==8)
goto backtrack; //wrong
//row test
for (int i = 0; i
if (b[r][i]==1) goto NR;
}
//up diagnal test
for (int i = 1; (r-1)>=0 && (c-1)>=0; i++){
if (b[r-1][c-i]=1)
goto NR;
}
// down diagnal test
for (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;
cout << b[r][c] ;
Print:
cout << b[r][c];
goto backtrack;
}
Here is my codes for the 8 queens problem, however I am having a hard time to find out how to print the result, I already know the result is 92 but still not able to find a way to print. Can any expert help me find out what is wrong with my codes? Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
