N Queen Problem using c and c++
Here you will get a 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 chessboard such that no two queens are in the same row, column or diagonal. In this tutorial, I am sharing the C program to find a solution for N Queens problem using backtracking. Below animation shows the solution for 8 queens problem using backtracking.
#include<stdio.h>
#include<conio.h>
#include<math.h>
int x[100];
void main()
{
clrscr();
void n_queen(int,int);
int n;
printf("\n\t Enter Queen Value : ");
scanf("%d",&n);
n_queen(1,n);
getch();
}
void n_queen(int k,int n)
{
int p(int ,int);
for(int i=1;i<=n;i++)
{
if(p(k,i))
{
…
Comments
Post a Comment