#include #include #include int main(){ srand(time(NULL)); int board[9][9]; int num[9]={1,2,3,4,5,6,7,8,9}; for(int i =0;i<9;i++) { if(i%3==0) { for(int j =0;j<9;j++) { int k =rand()%9; int temp = num[j]; num[j] = num[k]; num[k] = temp; } } for(int j = 0;j<9;j++) //定义矩阵各元素为0 { board[i][j] = 0; } for(int m = 0;m<3;m++) { int index; do{ index = rand()%9; }while(board[i][index]!=0); board[i][index] = num[3*(i%3)+m]; } } printf("The original Sudoku matrix: \n"); //格式化输出 for(int i=0;i<9;i++){ if(i%3==0){ printf("-------------\n"); } for(int j=0;j<9;j++){ if(j%3==0||j==9){ printf("|"); } printf("%d",board[i][j]); } printf("|\n"); }printf("-------------\n"); return 0; }