Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

somebody helped with this but it doesnt print anything at all, then other expert said try debugging, but it still doesnt anbody how to print?

somebody helped with this but it doesnt print anything at all, then other expert said try debugging, but it still doesnt anbody how to print?

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

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

L01 Distinguish among leading models of emotion.

Answered: 1 week ago

Question

Explain in detail how the Mughal Empire was established in India

Answered: 1 week ago

Question

Problem: Evaluate the integral: I - -[ze dx

Answered: 1 week ago

Question

Problem: Evaluate the integral: I = 1- 1 dx 9

Answered: 1 week ago