From fc98e180162bafb2e5ac1cde78efb4b3f3827852 Mon Sep 17 00:00:00 2001 From: pcn3xiqjt <2556107223@qq.com> Date: Sun, 29 Oct 2023 10:26:57 +0800 Subject: [PATCH] ADD file via upload --- 2random matrix.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 2random matrix.c diff --git a/2random matrix.c b/2random matrix.c new file mode 100644 index 0000000..40e2402 --- /dev/null +++ b/2random matrix.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); + 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"); + + +}