answersLogoWhite

0

#include<stdio.h>

#include<conio.h>

#include<math.h>

int a[30],count=0;

int place(int pos)

{

int i;

for(i=1;i<pos;i++)

{

if((a[i]==a[pos])((abs(a[i]-a[pos])==abs(i-pos))))

return 0;

}

return 1;

}

void print_sol(int n)

{

int i,j;

count++;

printf("\n\nSolution #%d:\n",count);

for(i=1;i<=n;i++)

{

for(j=1;j<=n;j++)

{

if(a[i]==j)

printf("Q\t");

else

printf("*\t");

}

printf("\n");

}

}

void queen(int n)

{

int k=1;

a[k]=0;

while(k!=0)

{

a[k]=a[k]+1;

while((a[k]<=n)&&!place(k))

a[k]++;

if(a[k]<=n)

{

if(k==n)

print_sol(n);

else

{

k++;

a[k]=0;

}

}

else

k--;

}

}

void main()

{

int i,n;

clrscr();

printf("Enter the number of Queens\n");

scanf("%d",&n);

queen(n);

printf("\nTotal solutions=%d",count);

getch();

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What is the importance of stack algorithm in your program?

Stack implementations allow us to easily implement backtracking algorithms.


Who implements a unit's safety and health program?

Unit Commander


What is the difference between an algorithm and a program?

An algorithm is a step-by-step procedure for solving a problem, while a program is a set of instructions written in a programming language that implements an algorithm to perform a specific task on a computer. In simpler terms, an algorithm is like a recipe, and a program is like the dish you make using that recipe.


What DoD instruction implements the DoD CUI program?

The Department of Defense (DoD) instruction number 8500.01 implements the DoD Controlled Unclassified Information (CUI) Program. This instruction establishes the program and outlines the responsibilities of the Program Manager, the Designated Approving Authorities, and the CUI Program Office. The instruction also establishes the requirements for labeling, safeguarding, and disseminating CUI.


What is a method of developing software in which the programmer writes and implements a program in segments instead of waiting until the entire program is completed?

RAD (rapid application development)


What are the duties of a Program Integrator?

&bull; Acts as the "eyes and ears" of the PM &bull; Leads and directs the program support team (PST) &bull; Provides feedback and data to the PM &bull; Develops and implements program surveillance plans


Can you write a program that implements cramers rule for 2x2 and 3x3 matrix?

Yes I can. I did it in QBasic about 15 years ago.


What is the difference between agent function and agent program in AI?

From what I understand, agent function is a program that maps the percepts to action and update the internal state. an agent program actually implements the agent function


What is the relation between problem and programming?

Problem -&gt; Programming Programming can be a solution to a problem. If you have a problem and it can be solved by a computer program, so you can create such a program - so you can solve this problem by programming.


What is solution in c program?

The program itself is the solution. All programs are a solution to a given problem; that's the entire point of writing a program, to solve a problem. The program's algorithm specifies how the problem is solved and it's the programmer's job to convert that algorithm into working code.


What is the functinon of software patches?

A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.A patch is a fix for a problem in a computer program. When problems are found patches are applied and updates can later be prepared to resolve the problem completely.


What is structured overlay problem in program language?

what is over lay problem in programming design