OUTPUT SEEMS TO BE COMING WRONG

Can you please specify the error in my code?

#include
using namespace std;

static int ways=0;

bool isSafe(int **board,int i,int j,int n)
{
for(int row=0;row<i;row++)
{
if(board[row][j]==1)
return false;
}

int x=i;
int y=j;

while(x>=0 && y>=0)
{
    if(board[x][y]==1)
      return false;
    x--;
    y--;
}

x=i;
y=j;
while(x>=0 && y<n)
{
    if(board[x][y]==1)
      return false;
    x--;
    y++;
}

return true;

}

bool solveNQueen(int **board,int i,int n,int ways)
{
if(i==n)
{
ways++;
cout<<ways;
return false;
}

for(int j=0;j<n;j++)
{
    if(isSafe(board,i,j,n))
    {
        board[i][j]=1;
        bool queenRakhPaaye=solveNQueen(board,i+1,n,ways);
        if(queenRakhPaaye)
        {
            return true;
        }
        board[i][j]=0;
    }
    
}
return false;

}

int main()
{
int n,i,j;
cin>>n;
int *board=new int[n];
for(i=0;i<n;i++)
board[i]=new int[n];

for(i=0;i<n;i++)
   for(j=0;j<n;j++)
      board[i][j]=0;
solveNQueen(board,0,n,ways);

}

hi @Mukul-Shane-1247687648773500,
please share the code link by saving in ide.codingblocks.com,
the code is not readable here

#include using namespace std; static int ways=0; bool isSafe(int **board,int i,int j,int n) { for(int row=0;row<i;row++) { if(board[row][j]==1) return false; } int x=i; int y=j; while(x>=0 && y>=0) { if(board[x][y]==1) return false; x–; y–; } x=i; y=j; while(x>=0 && y<n) { if(board[x][y]==1) return false; x–; y++; } return true; } bool solveNQueen(int **board,int i,int n,int ways) { if(i==n) { ways++; cout<<ways; return false; } for(int j=0;j<n;j++) { if(isSafe(board,i,j,n)) { board[i][j]=1; bool queenRakhPaaye=solveNQueen(board,i+1,n,ways); if(queenRakhPaaye) { return true; } board[i][j]=0; } } return false; } int main() { int n,i,j; cin>>n; int *board=new int[n]; for(i=0;i<n;i++) board[i]=new int[n]; for(i=0;i<n;i++) for(j=0;j<n;j++) board[i][j]=0; solveNQueen(board,0,n,ways); }

@Mukul-Shane-1247687648773500, the code is not readable on this platform…ok listen you just submit thi code on the ide I’ll get it… Or try saving in online ide

I have submitted the code here.4 TEST CASES ARE SHOWING WRONG OUT OF 5.

@Mukul-Shane-1247687648773500,
check updated code https://ide.codingblocks.com/s/660734

The code editor is showing a blank white screen. Unable to type and submit the code.Is something wrong with the site at the time?

@Mukul-Shane-1247687648773500, maybe try again… Btw not for me

its still showing a blank white screen .

@Mukul-Shane-1247687648773500 maybe some backend issue try submitting tomorrow still not working contact [email protected]

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.