You are on page 1of 1

#include<iostream>

#include<math.h>
using namespace std;
main()
{
int x[1000],n,i,cont,j,s=1;
i=1;
x[i]=0;
cout<<"n=";cin>>n;
while(i>0)
{
while(x[i]<n)
{
x[i]=x[i]+1;
cont=1;
for(j=1;j<=i-1;j++)
if(x[i]==x[j]||fabs(x[i]-x[j])==i-j)
cont=0;
if(cont)
{
if(i==n)
{
cout<<"Solutia "<<s<<endl;
s++;
for(int t=1;t<=n;t++)
{
for(j=1;j<=n;j++)
if(x[t]==j)
cout<<"X ";
else
cout<<"| ";
cout<<endl;}
}
else
{ i=i+1;
x[i]=0;}
}
}
i=i-1;
}
cout<<endl<<"Sunt "<<s<<" solutii.";
}

You might also like