Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started