*************solve n quen

exactly same code written by sir still no output is coming
#include
using namespace std;

bool isSafe(int board[][10], int i, int j, int n){
//you can check for column
for(int row=0;row<i;row++){
if(board[row][j]==1){
return false;
}
}

//you can check for left diagonl
int x = i;
int y = j;
while(x>=0 && y>=0)
{
    if(board[x][y]==1){
        return false;
    }
   x--;
   y--;
}

//you can check for right diagonal
x = i;
y = j;
while(x>=0 && y<n)
{
    if(board[x][y]==1){
        return false;
    }
   x--;
   y++;
}
//the position is now safe, column and diagonals
return true;

}
bool solveNQueen(int board[][10],int i, int n){
//base case
if(i==n){
//you hav successfully place queens in n rows( 0,…,n-1);
//print the board;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(board[i][j]==1){
cout<<“Q”;
}
else{
cout<<"_ ";
}
}
cout<<endl;
}
return true;
}
//rec case
//try to place the queen in the current row and call on the remaining mart which will b done by recursion
for(int j=0;j<n;j++){
//i hav to check if i,j th position is safe to place the queen or not
if(isSafe(board,i,j,n)){
//place the queen - assuming i,j is the correct position
board[i][j]=1;

        bool nextQueenRakhPaye = solveNQueen(board,i+1,n);
        if(nextQueenRakhPaye){
            return true;
        }
       //means i,j if not the correct position - Assumption is wrong
       board[i][j]=0;//backtrack
    }
}
//you hav tried all positions in a current row but couldn't place the queen
return true;

}

int main(){
int n;
cin>>n;
int board[10][10] = {0};

solveNQueen(board,0,n);

return 0;}

@ayu2321
Please share your code on CB IDE

my cb ide doesnot work well

@ayu2321
You can try ideone then
and you can mail [email protected] for help with IDE

@ayu2321
Rather silly error
Line 75
return false;
not
return true;
:slight_smile:

If your doubt is resolved please close it.

by doing this only one configuration is coming but we need to print all the configurations

@ayu2321
Your code is for only configuration
Modify it accordingly if you need all