Question: Complete the dumb 8 queens program that we looked at in lecture. Use the 1 dimensional array representation. can somebody find the solution for me

Complete the "dumb" 8 queens program that we looked at in lecture. Use the 1 dimensional array representation.

can somebody find the solution for me using this code, I dont know why this is stuck. I already know. the problem, but I am not find a silution for it so whoever is going to answer can you make sure that the code work please! PLEASE CHECK IT WORKS AND PRINTS THE BOARD!!!!

#include

#include

using namespace std;

bool ok(int q[], int c) {

for (int i = 0; i < c; i++) {

if (q[i] == q[c] || abs(q[c] - q[i]) == c - i) {

return false;

}

}

return true;

}

void print(int q[]) {

for (int i = 0; i < 8; i++) {

cout << q[i] << " ";

}

cout << endl;

}

int main() {

int board[8] = {0};

int col = 0;

while (col >= 0) {

if (col == 8) {

print(board);

col--;

} else if (board[col] == 8) {

board[col] = 0;

col--;

} else if (ok(board, col)) {

col++;

} else {

board[col]++;

}

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!