Update sudoku1.c

main
pq2zv6pm4 1 year ago
parent bb919bd3ae
commit bca9e32542

@ -1,35 +1,34 @@
/*-------------------*/ /*-------------------*/
/*实验:数独矩阵------*/ /*实验:数独矩阵------*/
/*1.9×9 数组格式化输出;*/ /*1.9×9 数组格式化输出;*/
/*-------------------*/ /*-------------------*/
#include<stdio.h> #include<stdio.h>
#include<stdlib.h> #include<stdlib.h>
void printBoad(int _board[9][9]){ void printBoad(int _board[9][9]){
int i,j; int i,j;
for ( i = 0; i < 9;i++){ for ( i = 0; i < 9;i++){
if(!(i%3))printf("|-----------------------|\n"); if(!(i%3))printf("|-----------------------|\n");
for ( j = 0; j < 9;j++){ for ( j = 0; j < 9;j++){
if(!(j%3)) if(!(j%3))
printf("| "); printf("| ");
if(_board[i][j]==0) if(_board[i][j]==0)
printf(". "); printf(". ");
else else
printf("%d ", _board[i][j]); printf("%d ", _board[i][j]);
} }
printf("|\n"); printf("|\n");
} }
printf("|-----------------------|\n"); printf("|-----------------------|\n");
} }
int main(){ int main(){
randseedInit(); int board[9][9]={{5,3,4,6,7,8,9,1,2},
int board[9][9]={{5,3,4,6,7,8,9,1,2}, {6,7,2,1,9,5,3,4,8},
{6,7,2,1,9,5,3,4,8}, {1,9,8,3,4,2,5,6,7},
{1,9,8,3,4,2,5,6,7}, {8,5,9,7,6,1,4,2,3},
{8,5,9,7,6,1,4,2,3}, {4,2,6,8,5,3,7,9,1},
{4,2,6,8,5,3,7,9,1}, {7,1,3,9,2,4,8,5,6},
{7,1,3,9,2,4,8,5,6}, {9,6,1,5,3,7,2,8,4},
{9,6,1,5,3,7,2,8,4}, {2,8,7,4,1,9,6,3,5},
{2,8,7,4,1,9,6,3,5}, {3,4,5,2,8,6,1,7,9}};
{3,4,5,2,8,6,1,7,9}}; printBoad(board);
printBoad(board); }
}

Loading…
Cancel
Save