Login

C Programming 8 Queens Problem with Recursive Function

8 Queens Problem Solving with Recursion in C Programming

In the game of chess, the queen can attack any piece that lies on the same row, on the same column, or along a diagonal. The eight-queens is a classic logic puzzle. The task is to place 8 queens on a chessboard in such a fashion that no queen can attack any other queen

A fun problem that can be solved using recursion is the Eight Queens Problem. The goal is to place 8 queens on a chessboard so that none is in the same row or column or diagonal of the board. Consider a recursive function such as subsets or permutation that makes not just one recursive call, but several. The tree of function calls has multiple branches at each level, which in turn have further branches, and so on down to the base case. The Reclusive function for 8 Queens problem assume to ensure that the following conditions
1. No two queens share a column
2. No two queens share a row
3. No two queens share a / diagonal
4. No two queens share a \ diagonal

The Output of the above 8 Queens Problem will bet[1] = [1] // The first square of the first row
t[2] = [5] // The fifth square of the second row
t[3] = [8] // The eight square of the third row
t[4] = [6] // The sixth square of the fourth row
t[5] = [3] // The third square of the fifth row
t[6] = [7] // The seventh square of the sixth row
t[7] = [2] // The second square of the seventh row
t[8] = [4] // The fourth square of the eighth row