Code:

#include <iostream>
using namespace std;
void displayBoard(int size);
void addQueen(int row, int column);
void removeQueen(int row,int column);
void solve(int size, int column, int row);
bool isPathViable(int row, int column);
const int size = 8;
int board[size][size] = {0};
int main()
{
for(int i=0;i < size;i++)
solve(size,i,0);
return 0;
}
void solve(int size,int row, int column)
{
if(isPathViable(row,column))
{
addQueen(row,column);
if(column == size - 1)
{
displayBoard(size);
}
else
{
for(int i=0; i < size; ++i)
{
if(i != row)
solve(size,i,column+1);
}
}
removeQueen(row,column);
}
return ;
}
bool isPathViable(int row, int column)
{
for(int i=column-1;i >= 0; --i) //Checks row
{
if(board[row][i]==1)
return false;
}
for(int j=row-1, k=column-1 ; j >= 0, k >= 0;--j, --k) //Checks left and up diagonal
{
if(board[j][k]==1)
return false;
}
for(int u=row+1, h=column-1 ;u >= 0,h >= 0;++u,--h) //Checks left and down diagonal
{
if(board[u][h]==1)
return false;
}
return true;
}
void displayBoard(int size)
{
for(int i=0; i < size; ++i)
{
for(int j=0; j < size; ++j)
cout << board[i][j] << " ";
cout << "\n";
}
cout << "\n";
cout << "\n";
}
void addQueen(int row,int column)
{
board[row][column]=1;
}
void removeQueen(int row,int column)
{
board[row][column]=0;
}

find n differencies...