From 0aa697d4506b04346dea840b5c99217396be75d0 Mon Sep 17 00:00:00 2001 From: pngtmzsyq <864002285@qq.com> Date: Tue, 31 Oct 2023 16:24:01 +0800 Subject: [PATCH] ADD file via upload --- suiji.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 suiji.c diff --git a/suiji.c b/suiji.c new file mode 100644 index 0000000..e2ece7d --- /dev/null +++ b/suiji.c @@ -0,0 +1,52 @@ +#include +#include +#include +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; +}