Question: 1. Need help to run this following 1-dimensional array 8 queens program. How can I fix the (print section) and What do I have to
1. Need help to run this following 1-dimensional array 8 queens program. How can I fix the (print section) and What do I have to add to the (print section) at the end to run this program? the code should give you 92 times. I mean 92 different answers. Each its own specific row.
After running this program correctly with goto statements, follow the question #2.
2.Redo the 8 queens 1-dimensional array program with backtracking REMOVING ALL "GOTOs" - but implementing the same algorithm.
#include
int main(){ int q[8], //1D array representation of the chess board c = 0; //column index, initially 0 q[0] = 0; //putting 1st queen piece on upper-left corner
next_col:
++c; //advance column position if (c == 8) //solutions for columns 0 through 7 found, goto print; //so print q[c] = -1; //otherwise start at the top of the column
next_row:
++q[c]; //advance row position if (q[c] == 8) //tried all rows in current column, none work, goto backtrack; //so we backtrack
for (int i = 0; i
backtrack:
--c; //go back one column if (c == -1) //if past first column, all solutions found, return 0; //so terminate program goto next_row; //move on to next row
print:
print(q); //print the board goto backtrack; //go back to find more solutions
The program should give you something like this after run the program.

0 47 5 2 6 1 3 0 5 7 2 6 3 1 4 0 6 3 5 7 1 4 2 0 6471352 1 3 5 7 20 6 4 1 4 6 0 2 7 53 7 1 4 6 3 075 2 15 0 6 3 7 24 1 5 7 2 0 3 6 4 1e 16 25 74 03 16 47 0 3 5 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
