From 5acb5136d2354c7de5480063ec2e8ee9047443f0 Mon Sep 17 00:00:00 2001 From: p5fohke9s <837368911@qq.com> Date: Thu, 7 Nov 2024 23:15:10 +0800 Subject: [PATCH] ADD file via upload --- f2.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 f2.c diff --git a/f2.c b/f2.c new file mode 100644 index 0000000..064b7a4 --- /dev/null +++ b/f2.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +int used[10]; + +void row(int row[]){ + int nums[3]; + int numcount=0; + while(numcount < 3){ + int num=rand()%9+1; + if(!used[num]){ + nums[numcount++]=num; + used[num]=1; + } + } + int i; + for ( i=0;i < 3; i++) { + int index; + do{ + index=rand()%9; + }while(row[index] != 0); + row[index]=nums[i]; + } +} +int main(){ + int i,j; + int a[10][10]; + srand((unsigned)time(NULL)); + for ( i = 0; i < 9; i++){ + for( j=0; j < 9; j++){ + a[i][j]=0; + } + if(i % 3 == 0) + memset(used, 0, sizeof(used)); + row(a[i]); + } + + for(i=0;i < 9;i++){ + for( j=0;j < 9;j++) { + printf("%d ",a[i][j]); + + } + printf("\n"); + } + return 0; +}