From 8cb34280af053fbd7dbd59378456a89f383874ad Mon Sep 17 00:00:00 2001 From: p56isruwj <3475735425@qq.com> Date: Mon, 6 Nov 2023 21:50:44 +0800 Subject: [PATCH] ADD file via upload --- 题目2.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 题目2.cpp diff --git a/题目2.cpp b/题目2.cpp new file mode 100644 index 0000000..fa308f2 --- /dev/null +++ b/题目2.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +int a[10][10]={0}; +int number=0; +void randomquene(int array[], int len) +{ + srand(time(NULL)); + for (int i=len-1;i>0;i--) + { + int j=rand()%(i+1); + int temp=array[i]; + array[i]=array[j]; + array[j]=temp; + } +} +void randomputs(int array[],int len) +{ + for(int row=1;row<10;row++) + { + int k=1; + while(k<4) + { + int col=rand()%9+1; + if(a[row][col]==0) + { + a[row][col]=array[number]; + number++; + k++; + } + } + if(row%3==0) + { + number=0; + randomquene(array,len); + } + } +} +void format(int s[][10]) +{ + printf("-------------------------\n"); + for(int i=1;i<10;i++) + { + printf("| "); + for(int j=1;j<10;j++) + { + + printf("%d ",s[i][j]); + if(j%3==0) printf("| "); + } + printf("\n"); + if(i%3==0) printf("-------------------------\n"); + } +} +int main() +{ + int array[]={1, 2, 3, 4, 5, 6, 7, 8, 9}; + int len=sizeof(array)/sizeof(array[0]); + randomquene(array,len); + randomputs(array,len); + format(a); + return 0; +} +