What's New-Given Below
technicalsymposium
technicalsymposium
technicalsymposium

College Lab Codings/Project Codings-Download

Technicalsymposium.com-Receive Latest Updates through Facebook-Like us Below

NQUEEN PROBLEM
#include<stdio.h>
void main()
{
int i,k=0,n,row[15],ddiag[20],udiag[20];
int board[15],r,j;
clrscr();
printf("\n\t\tN QUEEN'S PROBLEM\n\n");
printf("\n\tEnter the No. of Queens to be placed : ");
scanf("%d",&n);
for(i=0;i<n;i++)
board[i]=row[i]=0;
for(i=0;i<(2*n);i++)
ddiag[i]=udiag[i]=0;
while(1)
{
r=board[k];
if(!row[r] && !ddiag[n-1-k+r] && !udiag[k+r])
{
row[r]=ddiag[n-1-k+r]=udiag[k+r]=1;
k++;
if(k==n)
{
printf("\n\n\t\tSOLUTION\n\n ");
for(i=0;i<n;i++,printf("\n\n "))
for(j=0;j<n;j++,printf(" "))
if(j==board[i])
printf("Q");
else
printf("-");
getch();
exit(0);
}
else
board[k]=0;
}
else
{
board[k]++;
while(board[k]==n)
{
k--;
row[board[k]]=0;
ddiag[n-1-k+board[k]]=0;
udiag[k+board[k]]=0;
board[k]++;
}
}
}
}

Hosting by Yahoo!

About-Us    Contact-Us    Site-map

©copyright 2009 All rights are reserved to technicalsymposium.com