You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
675 B

#include "myMatrix.h"
void matrixRandomInit(int matrixArr[9][9]){
int map[9] = {1,2,3,4,5,6,7,8,9};
int mp;
srand(time(NULL));
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
matrixArr[i][j] = 0;
}
}
for(int i=0;i<9;i++){
if(i%3==0){
mp=0;
for(int j=0;j<8;j++){
int n = i+rand()%(8-i);
int tmp = map[i];
map[i] = map[n];
map[n]=tmp;
}
}
int k=0;
while(k<3){
int tmpP = rand()%9;
if(matrixArr[i][tmpP]==0){
matrixArr[i][tmpP] = map[mp++];
k++;
}
}
}
}
int main(){
int board[9][9];
matrixRandomInit(board);
matrixOutput(board);
return 0;
}