0

Arrays- 2D question

Write a program to place 8 queens on an 8×8 chessboard in such a way that 1 Q is to be on each row. Ask the user to enter the columns that contain queens in the 8 rows. The program then places the queens in these columns (1 per row) and prints the board.

18th Mar 2020, 6:56 PM
Janvi
3 Answers
0
You can do this by Initializing a 2d array and keep all the elements of array 0 at the time of Initialization. When you put a Queen on any position, replace that 0 by 1. I think there is another constraint in your problem that No queen should attack each other, otherwise without this constraint your problem should be very trivial. This is a very famous problem in AI called "n - Queens problem". Where n is variable.
18th Mar 2020, 7:18 PM
Vijay Meena
0
I did try it but it gave me no solution
18th Mar 2020, 7:15 PM
Janvi
0
Could you try to help with the coding please
18th Mar 2020, 8:04 PM
Janvi