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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started