I do not know if these are the only errors, but at first glance I think instead
if (count == 1 && arr[r][c] == 0) { tempNum = num; } else { tempNum = 0; } count++;
he should be
count++; if (count == 1) { tempNum = num; }
and instead
if (count == 1 && check(r, c, num) && arr[r][c] == 0) { arr[r][c] = tempNum;
he should be
if (count == 1 && check(r, c, tempNum)) { arr[r][c] = tempNum;
or simply
if (count == 1 ) { arr[r][c] = tempNum;
because when count==1 , then check(r, c, tempNum) cannot be false if your check function has no side effects.
By the way, the code becomes much better readable if you arrange it as follows:
for (int r = 0; r < MAX_ROW; r++) { for (int c = 0; c < MAX_COL; c++) { if(arr[r][c] != 0) continue; // ** no tests for arr[r][c] == 0 in this code block any more // ... } }
And the last: you have to stop the algorithm, if the number of zeros in the outer loop no longer changes from one iteration to another, there will be SuDoKus, which your solver cannot solve, and you do not want to force you to program in an infinite loop for these, I think.
source share