Complete the 8 queens 2 dimensional array

Assignment Help C/C++ Programming
Reference no: EM13167720

Complete the 8 queens 2 dimensional array program with backtracking. please change the below program using backtracking  and please run before posting it . the program suppose to print 92 solution . amd also comment before each line to better understand.


#include <cmath> #include <iostream> using namespace std; bool ok(int board[][8]){ for(int c = 7; c > 0; c--){ int r = 0; while(board[r][c] != 1 ){ r++; } for(int i = 1; i <= c; i++){ if(board[r][c-i] == 1) return false; else if (board[r-i][c-i] == 1) return false; else if (board[r+i][c-i] == 1) return false; } } return true; } void print(int board[][8], int count){ cout << count << endl; for(int i = 0; i < 8; i++){ for(int j = 0; j < 8; j++){ cout << board[i][j]; } cout << endl; } } int main (){ int board[8][8]; for ( int i = 0; i < 8; i++ ) for ( int j = 0; j < 8; j++ ) board[i][j] = 0; int count = 0; for(int i0 = 0; i0 < 8; i0++) for(int i1=0; i1 < 8; i1++) for(int i2 = 0; i2 < 8; i2++) for(int i3 = 0; i3 < 8; i3++) for(int i4 = 0; i4 < 8; i4++) for(int i5 = 0; i5 < 8; i5++) for(int i6 = 0; i6 < 8; i6++) for(int i7 = 0; i7 < 8; i7++){ board[i0][0]=1; board[i1][1]=1; board[i2][2]=1; board[i3][3]=1; board[i4][4]=1; board[i5][5]=1; board[i6][6]=1; board[i7][7]=1; if(ok(board))print(board, ++count); board[i0][0]=0; board[i1][1]=0; board[i2][2]=0; board[i3][3]=0; board[i4][4]=0; board[i5][5]=0; board[i6][6]=0; board[i7][7]=0; } return 0; }

Reference no: EM13167720

Questions Cloud

Binary relation on s for reflexivity, symmetry, antisymmetry : Let S={1,2,3,4,5,6,7,8}. Test the following binary relation on S for reflexivity, symmetry, antisymmetry, and transitivity
Find the domain for each of two rational expressions : Find your two rational expressions in the list below based on the first letter of your first name and explain in your own words what the meaning of domain is. Also, explain why a denominator cannot be zero.
Program consists of a 200-instruction : A given program consists of a 200-instruction loop that is executed 50 times. If it takes 20,000 cycles to execute the program on a given system, what are that system's cycle per instruction
The single processor system : Suppose further that a single processor system can solve the problem in 106 seconds (about 11.6 days). So, on average, the single processor system
Complete the 8 queens 2 dimensional array : Complete the 8 queens 2 dimensional array program with backtracking. please change the below program using backtracking  and please run before posting it . the program suppose to print 92 solution . amd also comment before each line to better unde..
Horizontal distance of the tire valve : Define a function that gives the horizontal distance of the tire valve to the right of the tire's vertical diameter ...
Design and draw the state diagram : Design and draw the state diagram (graph-representation) of a deterministic finite-state automata that recognizes the language generated by the grammar
T an array using insertion sort and track the number of swap : How to sort an array using insertion sort and track teh number of swaps during the sorting
Quality of building management : What role does the quality of building management and operations play vis-a-vis a strictly technological approach to energy efficiency? Why?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Demonstrate the construction and output of an array

In fluid mechanics, the Reynolds number (Re) is a dimensionless quantity that is used to help predict similar flow patterns in different fluid flow situations. For example, Reynolds numbers can be computed for different velocities of fluid flow over ..

  Array of integers declared-initialized to number of tickets

Array of integers named parkingTickets has been declared and initialized to number of parking tickets given out by city police each day as beginning of current year.

  Iterative programming problem solving approaches

Write a recursive function void reverse ( ) that reverse a sentence

  Given a character code to indicate the type of customer

Pete's Plumbing of Pompey sells to both retail and wholesale buyers. The retail buyer must pay New York State and Onondaga County sales tax (8%). However, the wholesale buyer does not pay sales tax and receives a volume discount on the amount purchas..

  Squares, triangles, circles and ellipses

write a program which will answer a pair of questions for squares, triangles, circles and ellipses. A square is defined by its lower left corner ( S L L x , S L L y ), and the length of one side  S W .

  Use the top-down modular approach to design program

Use the top-down modular approach and pseudocode to design a suitable program to solve it. Where appropriate, use defensive programming techniques.

  Programmingto compute the volume of water in the cubic feet

Write down an algorithm (Programming in C) in order to compute the volume of water in the cubic feet, flowing through a pipe of diameter d in feet, having a velocity of v feet per second.

  Calculates average of three exams for each student

The program reads the grades for students, calculates average of three exams for each student, and puts out to another file (called Summarygrades.txt) Student ID average and letter grade: example below,

  Define two derived classes of the abstract class

Define two derived classes of the abstract class ShapeBase below. Your two classes will be called RightArrow and LeftArrow. These classes will draw arrows that point right and left,

  Write a program to crypt its input accordingly

Write a program to crypt its input according to a specified transformation scheme

  Create a global array of structures

Create a global array of structures with the following data. Each structure should store the data (Employee Table - Name, age, salary information) . Array size must be at least 10

  Write a program that asks the user to enter the names of 3

Write a program that asks the user to enter the names of three salesmen. The program should thenaccept the sales produced for salesman for each quarter of the year. Display the name, and the totalsales amount, of each salesman.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd