Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions