From fc6628b848f64b481c950e7b9341a1a72074e94c Mon Sep 17 00:00:00 2001 From: p3z2sacvh <1103413762@qq.com> Date: Fri, 3 Nov 2023 12:40:00 +0800 Subject: [PATCH] ADD file via upload --- 题目2.txt | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 题目2.txt diff --git a/题目2.txt b/题目2.txt new file mode 100644 index 0000000..b49208d --- /dev/null +++ b/题目2.txt @@ -0,0 +1,55 @@ +#include +#include +#include +int main() +{ + int board[9][9]={{0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}}; + + int flag[9][9]={{0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0}}; + + srand(time(NULL)); + int i,j,p,num; + + for(i=0;i<9;i++) + { + for(j=0;j<3;j++) + { + do{ + p=rand()%10; + }while(p>=9 || board[i][p]!=0); + do{ + num=rand()%10; + }while(num==0 || flag[i][num]==1); + board[i][p]=num; + flag[i][num]=1; + } + } + + for(i=0;i<9;i++) + { + if(i%3==0) printf("|-----------------------|\n"); + for(j=0;j<9;j++) + { + if(j%3==0) printf(j==0?"|":" |"); + printf(" %d",board[i][j]); + } + printf(" |\n"); + } + printf("|-----------------------|\n"); +}