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

  The user enter the total rainfall for each of 12 months

Write a program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display:the total rainfall for the year,the average monthly rainfall,and the months w..

  In psuedocode, design an application

In psuedocode, design an application that has an array of at least 20 integers. It should call a module that uses the sequential search algorithm to locate one of the values

  Local diner that allows customers to see the diner''s menu

Design a program to be used for a small local diner that allows customers to see the diner's menu and then make their meal selections using the program.The program will also calculate and print an itemized bill.

  Use functional decomposition to solve

Use functional decomposition to solve this problem, and code the solution using functions wherever it makes sense to do so. Your program should check for invalid data such as nonpositive dimensions, number of rooms less than 1.

  Program to enter number of values to be processed

Write c++ statements to permit the user to enter n, the number of values to be processed; then assign the anonymous array of n double values, storing its address in doublPtr.

  Calculates the sum of the cube roots of two integers.

Wrtie a program that calculates the sum of the cube roots of two integers. The program should use the following functions as well as a main funcion. 1) enter one positive value 2) compute the cube root of one integer 3) report the value of two intege..

  Store a list of student info

Store a list of student info, (id number, First name and Last name) using a link list. The ID is the key field. The program should implement a linked list using arrays.The program should process the following operations

  Design a simple atm service kiosk

Design a simple ATM service kiosk. This kiosk supports the following options for its menu: 1. Viewing your account balance2. Depositing cash3. Withdrawing cash

  Prepare a linux shell

Prepare a linux shell (in other words, write a C/C++ program) that will recursively prompt for input from the user. The shell should prompt as

  Write a c program that reads a data file of floating numbers

Write a program that reads a data file of floating numbers into an array and prints the array elements along with the number of items in the array

  Write in c++ another overloaded operator

Write in C++ another overloaded operator to go in the program that has Treasury. Overload the forward slash /  so that in the main program, you can declare sale to be of type Treasury, and commission to be of type Treasury, and commispctage to be of ..

  Write a function that accepts an int array

The task calls for: Write a function that accepts an int array and the array's size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer t..

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