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

13y ago

What else can I help you with?

Continue Learning about Engineering

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)


White box testinglogic testing?

When you want to test a program, there is two types: white box testing and black box testing. Black box testing means you don't need to know about program implements or how it functions. Just program's requirements. White box testing, you must to check every ways your program should go to eliminate bugs.


What is a program Problem Statement?

A program problem statement is a clear, concise description of an issue or challenge that a program aims to address. It outlines the context, the specific problem, and the desired outcomes, serving as a foundation for developing solutions. A well-defined problem statement helps stakeholders understand the scope and significance of the issue, guiding the project’s objectives and approaches. Ultimately, it sets the stage for effective problem-solving and decision-making.


What is Runtime error 216 at 771544f1?

I fixed the problem by deleted the program 'Spyware Doctor' using the add or remove program Icon in Control Panel. Once I rebooted the computer, the problem was gone.


What is circuit debugging?

Circuit debugging is a type of software program that tries to fix problems within the computer. For example, if a printer is not working properly that is attached to the computer, the debugging program can try to find out what the problem is. It may or may not automatically fix a problem.

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 the difference between simple program and function in C?

A function is a piece of code that has no or more arguments, that returns no or one value. A program is code that implements the function int main(int argc, char** argv). As such, a function and a program are the same, but the program also includes compiler directives to "include" other things, such as standard headers, i.e. #include .