Arrays- 2D question | Sololearn: Learn to code for FREE!


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.

3/18/2020 6:56:35 PM


3 Answers

New Answer


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.


I did try it but it gave me no solution


Could you try to help with the coding please