Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

find the problem in this code and please fix it #include #include using namespace std; bool ok(int q[], int c) { for (int i =

find the problem in this code and please fix it

#include #include using namespace std;

bool ok(int q[], int c) { for (int i = 0; i < c; i++) { if (q[i] == q[c] || c - i == abs(q[i] - q[c])) { return false; } } return true; }

void print(int q[]) { cout<< "Solution : "; for (int i = 0; i < 8; i++) { cout << q[i]; } cout << endl; }

int main() { int q[8] = {0}; int c = 0; while (c >= 0) { if (c == 7) { print(q); c--; } else if (q[c] == 8) { q[c] = 0; c--; } else if (ok(q, c)) { c++; } else { q[c]++; } } 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

explain what is meant by redundancy

Answered: 1 week ago