Question
somebody helped with this but it doesnt print anything at all Complete the dumb 8 queens program Use the 1 dimensional array representation. #include #include
somebody helped with this but it doesnt print anything at all
Complete the "dumb" 8 queens program Use the 1 dimensional array representation.
#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