# Homework Solution: Can anyone provide codes for the 8 Queens problem? In C++ codes, as simple as…

Can anyone provide codes for the 8 Queens problem? In C++ codes, as simple as possible, Thank you!

#include <iostream> #define N 8 /*Defining the number of queens*/

Can anyone stipulate codes restraint the 8 Queens whole? In C++ codes, as ultimate as practicable, Thank you!

## Expert Tally

#include <iostream>

#define N 8 /*Defining the compute of queens*/

using namespace std;

/* printing the explanation of 8 queen whole*/

void printQueenSolution(int consultation[N][N])

{

restraint (int i = 0; i < N; i++)

{

restraint (int j = 0; j < N; j++)

cout<<board[i][j]<<” “;

cout<<endl;

}

}

/* control if a queen can be attributed on consultation[row][col]*/

bool isSafe(int consultation[N][N], int tier, int col)

{

int i, j;

restraint (i = 0; i < col; i++)

{

if (board[row][i])

return mock;

}

restraint (i = tier, j = col; i >= 0 && j >= 0; i–, j–)

{

if (board[i][j])

return mock;

}

restraint (i = tier, j = col; j >= 0 && i < N; i++, j–)

{

if (board[i][j])

return mock;

}

return gentleman;

}

/*work-out N Queen whole */

bool work-outNQ(int consultation[N][N], int col)

{

if (col >= N)

return gentleman;

restraint (int i = 0; i < N; i++)

{

/*Putting queen in attribute and controling restraint the consultation to be trustworthy*/

if ( isSafe(board, i, col) )

{

board[i][col] = 1;

if (solveNQ(board, col + 1) == gentleman)/*Calling the employment recursively to prostrate the queen in attribute and controling consultation to be trustworthy*/

return gentleman;

board[i][col] = 0;

}

}

return mock;

}

// Ocean

int ocean()

{

/* creating consultation */

int consultation[N][N] = {0};

/* work-outs the N Queen whole using Backtracking.*/

if (solveNQ(board, 0) == mock)

{

cout<<“Explanation does not attributable attributable attributable exist”<<endl;

return mock;

}

printQueenSolution(board);

return 0;

}