sudoku row and column check

Hey all,
I was trying to make a sudoku solver for a 4 by 4 one, it all seems to be ok except the function where i am trying to compare the numbers in each row and column so that the numbers don't have a repetition. I have written this code, and I cant seem to find an error although it is showing some logical error. Assume the user had input the sudoku question in the main.

bool check_rowcol(int mainboard[4][4])
{
bool a=true;
int count_row=0;
int count_col=0;

for(int i=1;i<=4;i++)
{
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
if(mainboard[j][k]==i) count_row++;
if(mainboard[k][j]==i) count_col++;
}
if(count_row>1||count_col>1) a=false;
count_row=0; count_col=0;
}

}
return a;
}
Last edited on
You may find that it is easier to just check the row and column as each number is entered, rather than checking the validity of the entire board every time.
No Sir, this is actually a part of assignment where the part 1 asks me to make a function to check if the sudoku has a solution based on the user inputs, only if there is a solution then the solver() function gets activated.

Topic archived. No new replies allowed.