0% found this document useful (0 votes)
40 views5 pages

Mini Project On: N-Queens Algorithm

Uploaded by

Course 56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views5 pages

Mini Project On: N-Queens Algorithm

Uploaded by

Course 56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MINI PROJECT ON

N-QUEENS ALGORITHM

Submitted for the fulfilment of the curriculum Mini Project


required for DAA LAB for the FIFTH SEMESTER
DIPLOMA IN COMPUTER SCIENCE AND
ENGINEERING prescribed by BOARD OF TECHNICAL
EDUCATION, GOVT. OF KARNATAKA.

Submitted By
SAIKRISHNA

REG NO

408CS19011

HINDUSTAN ELECTRONICS ACADEMY POLYTECHNIC (408)

Marathalli, Bangalore-560037.
CODE:

#include<stdio.h>

#include<math.h>

int board[20],count;

void main()

int n,i,j;

void queen(int row,int n);

clrscr();

printf(" - N Queens Problem Using Backtracking -");

printf("\n\nEnter number of Queens:");

scanf("%d",&n);

queen(1,n);

getch();

void print(int n)

int i,j;

printf("\n\nSolution %d:\n\n",++count);

for(i=1;i<=n;++i)

printf("\t%d",i);
for(i=1;i<=n;++i)

printf("\n\n%d",i);

for(j=1;j<=n;++j)

if(board[i]==j)

printf("\tQ");

else

printf("\t-");

int place(int row,int column)

int i;

for(i=1;i<=row-1;++i)

if(board[i]==column)

return 0;

else

if(abs(board[i]-column)==abs(i-row))
return 0;

return 1;

void queen(int row,int n)

int column;

for(column=1;column<=n;++column)

if(place(row,column))

board[row]=column;

if(row==n)

print(n);

else

queen(row+1,n);

}
OUTPUT:

You might also like