#define N 8
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
bool a[8] = {true}; // 1 to 8
bool b[16] = {true}; // 2 to 16
bool c[16] = {true}; // -7 to 7
int x[8]; // 1 to 8
// for i = 1 to 8 do a[ i] = true;
// for i = 2 to 16 do b[ i] = true;
// for i = -7 to 7 do c[ i] = true;
void trythis(int i, bool q)
{
int j;
j = 0;
do
{
j = j + 1;
q = false;
if (a[ j] and b[ i + j] and c[ i - j])
{
x[ i ] = j;
a[ j ] = false;
b[ i + j] = false;
c[ i - j] = false;
if (i < 8)
{
trythis( i + 1, q);
if not q
{
a[ j] = true;
b[ i + j] = true;
c[ i - j] = true;
}
}
else
q = true
}
}
while not q or (j not= 8);
)
void eightqueen1(void);
{
int i;
bool q;
trythis( 1, q);
if q then
for (i = 1; i < 9; i++)
{
printf("%4d ", x[ i]);
}
printf("\n");
}
int main() // driver program to test above function
{
eightqueen1();
return 0;
}