Question

I have written a sudoku puzzle code that currently generates a valid sudoku board and then per-mutates each row within each band based on a random numbers 1-9 and then it will swap each row accordingly, however.

 for(q=0;q<9;q++){
    for(j=0;j<9;j++){
        printf("%2d",array[q][swap[j]-1]);
    }
        printf("\n");
}
Was it helpful?

Solution

This loop is not going to work:

while(q<9){
    for(q=0;q<9;q++){

Once the inner loop finishes, q is 9, so the outer loop will finish immediately. You should use two different loop counters. I think you just meant to have

for(j=0;j<9;j++){
    for(q=0;q<9;q++){

and not have g++,j++ in the loop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top