N Queens Problem in C Using Backtracking

Here you will get program for N queens problem in C using backtracking.

N Queens Problem is a famous puzzle in which n-queens are to be placed on a nxn chess board such that no two queens are in the same row, column or diagonal. In this tutorial I am sharing the C program to find solution for N Queens problem using backtracking. Below animation shows the solution for 8 queens problem using backtracking.

Also Read: C Program for Tower of Hanoi Problem


8 Queens Problem Using Backtracking
8 Queens Problem Using Backtracking


Program for N Queens Problem in C Using Backtracking



C Program for N Queens Problem Using Backtracking

Comment below if you found anything incorrect in above N queens problem in C.

9 thoughts on “N Queens Problem in C Using Backtracking

  1. arafat chowdhury

    #include will not declared in the scope fix it then it will work 🙂 thanks again to build up this dashing structure .

  2. Mandavi

    Hey Neeraj! can you please explain the code. I have got manual logic of n queen problem but finding code difficult to understand like board[i]=column and other such lines. Does board[i] or board[row] has some value. Please explain, i am a beginner….

  3. keshav

    I tried but i am not able to understand the logic :-
    if (abs(board[i]-column)==abs(i-row))

    How, it is able to check the column. please explain.

  4. Ankur

    thanks for the code, but I have a doubt.
    consider the first two queens are placed at (row 1, column1) and (row2 ,column 3). now the next queen can not be placed in row 3 and hence the position of 2nd queen is changing from (row2, column3) to (row2 ,column4).
    since, I can not see any code line to decrement the row number. can you please tell me how it is really executing this step???

  5. saikrishna vadali

    thank you so much bro 🙂 its hard to understand algorithm from textbook….. but u made it simple to understand through this program… thank you once again 🙂

  6. yashwanth

    explain in detail how place function is working. and what is abs?


Leave a Reply

Your email address will not be published. Required fields are marked *