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.
53 lines
920 B
53 lines
920 B
#include <stdio.h>
|
|
#include <time.h>
|
|
#include <stdlib.h>
|
|
void swap(int *a,int *b){
|
|
int temp;
|
|
temp=*a;
|
|
*a=*b;
|
|
*b=temp;
|
|
}
|
|
void shuffle(int *array,int size){
|
|
int i;
|
|
int j;
|
|
for(i=size-1;i>=0;i--){
|
|
j=rand()%(i+1);
|
|
swap(&array[i],&array[j]);
|
|
}
|
|
}
|
|
void print(int board[9][9]){
|
|
printf("|---|---|---|---|---|---|\n");
|
|
int i=0,j=0,s=0,k=0;
|
|
for(i=0;i<9;++i){
|
|
for(j=0;j<9;j++){
|
|
while(j%3==0){
|
|
printf("| ");
|
|
break;
|
|
}
|
|
printf("%d ",board[i][j]);
|
|
}
|
|
printf("|\n");
|
|
while((i+1)%3==0){
|
|
printf("|---|---|---|---|---|---|\n");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
int main(){
|
|
int board[9][9]={0};
|
|
int number[9]={1,2,3,4,5,6,7,8,9};
|
|
srand(time(NULL));
|
|
int i=0,j=0,k=0,s=0;
|
|
for(k=0;k<3;k++){
|
|
shuffle(number,9);
|
|
int column[3]={0,3,6};
|
|
for(i=0;i<3;i++){
|
|
for(j=0;j<3;j++){
|
|
board[k*3+i][column[j]]=number[i*3+j];
|
|
}
|
|
}
|
|
}
|
|
print(board);
|
|
return 0;
|
|
}
|