Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

Discuss the purpose and objectives of database marketing.

Answered: 1 week ago

Question

How does selection differ from recruitment ?

Answered: 1 week ago