W
wildthings
i was trying to complie/run the n queens problem on bloodshod
dev-c++(version4) as a c lang
project but it gives a huge no. of errors which i cant figure out
pls help
the code is:::
#include <iostream.h>
#include <stdlib.h>
#include <windows.h>
int c=0;
int try(int);
void drawboard(void);
int board[8][8];
int good();
int main()
{
int i,j;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
board[j]=0;
try(0);
printf("%d",c);
}
int try(int n)
{
int i;
for(i=0;i<8;i++)
{
board[n]=1;
if(n==7&&good()=1)
{
c++;
drawboard();
return(0);
}
if(n<7&&good()=1&&try(n+1)=1)
return(1);
board[n]=0;
}
return(0);
}
void drawboard()
{
inti,j;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
printf("%d",board[j]);
}
printf("/n");
}
int good()
{
int i,j,p,q;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
for(p=0;p<8;p++)
for(q=0;q<8;q++)
{
if(i==p||i==q||j==q||j==p||abs(i-p)==abs(j-q))
return(0);
else
return(1);
}
}
dev-c++(version4) as a c lang
project but it gives a huge no. of errors which i cant figure out
pls help
the code is:::
#include <iostream.h>
#include <stdlib.h>
#include <windows.h>
int c=0;
int try(int);
void drawboard(void);
int board[8][8];
int good();
int main()
{
int i,j;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
board[j]=0;
try(0);
printf("%d",c);
}
int try(int n)
{
int i;
for(i=0;i<8;i++)
{
board[n]=1;
if(n==7&&good()=1)
{
c++;
drawboard();
return(0);
}
if(n<7&&good()=1&&try(n+1)=1)
return(1);
board[n]=0;
}
return(0);
}
void drawboard()
{
inti,j;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
printf("%d",board[j]);
}
printf("/n");
}
int good()
{
int i,j,p,q;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
for(p=0;p<8;p++)
for(q=0;q<8;q++)
{
if(i==p||i==q||j==q||j==p||abs(i-p)==abs(j-q))
return(0);
else
return(1);
}
}