Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- int t[8] = {-1};
- int sol = 1;
- void printsol()
- {
- int i,j;
- char crossboard[8][8];
- for(i=0;i<8;i++)
- {
- for(j=0;j<8;j++)
- {
- crossboard[i][j]='_';
- }
- }
- for(i=0;i<8;i++)
- {
- crossboard[i][t[i]]='q';
- }
- for(i=0;i<8;i++)
- {
- for(j=0;j<8;j++)
- {
- printf("%c ",crossboard[i][j]);
- }
- printf("\n");
- }
- }
- int empty(int i)
- {
- int j=0;
- while((t[i]!=t[j])&&(abs(t[i]-t[j])!=(i-j))&&j<8)j++;
- return i==j?1:0;
- }
- void queens(int i)
- {
- for(t[i] = 0;t[i]<8;t[i]++)
- {
- if(empty(i))
- {
- if(i==7){
- printsol();
- printf("\n solution %d\n",sol++);
- }
- else
- queens(i+1);
- }
- }
- }
- int main()
- {
- queens(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement