Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!