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");
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.