From 5051c73120098fa33b6fe132c97242636f6d124f Mon Sep 17 00:00:00 2001 From: pcn3xiqjt <2556107223@qq.com> Date: Tue, 31 Oct 2023 09:35:28 +0800 Subject: [PATCH] ADD file via upload --- 2随机矩阵.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 2随机矩阵.c diff --git a/2随机矩阵.c b/2随机矩阵.c new file mode 100644 index 0000000..eedc8d7 --- /dev/null +++ b/2随机矩阵.c @@ -0,0 +1,68 @@ +#include +#include +#include +int main(){ + srand(time(NULL)); + int i,j,numa,numb,numc; + char board[9][9],num[9]; + memset(board,0,sizeof(board)); + memset(num,0,sizeof(num)); + int randchar(char* c){ + int i,j,temp,numa,numb; + for(j=0;j<9;j++){ + c[j]=j+1; + } + for(i=0;i<50;i++){ + numa=rand()%9; + do{ + numb=rand()%9; + }while(numb==numa); + temp=c[numa]; + c[numa]=c[numb]; + c[numb]=temp; + } + //return c; + + } + + for(i=0;i<3;i++){ + randchar(num); + for(j=0;j<3;j++){ + numa=rand()%9; + do{ + numb=rand()%9; + }while(numb==numa); + do{ + numc=rand()%9; + }while(numc==numa&&numc==numb); + board[j+3*i][numa]=num[0+3*j]; + board[j+3*i][numb]=num[1+3*j]; + board[j+3*i][numc]=num[2+3*j]; + } + + } + for(i=0;i<9;i++){ + if(i==0||i==3||i==6){ + printf("|-----------------------|\n"); + } + printf("| "); + for(j=0;j<9;j++){ + if(board[i][j]!=0){ + printf("%d ",board[i][j]); + } + else{ + printf(". "); + } + if(j==2||j==5||j==8){ + printf("| "); + } + if(j==8){ + printf("\n"); + } + } + + } + printf("|-----------------------|\n"); + + +}