From b7d885f41320e45e64cab581f5b63dcc8f73dea3 Mon Sep 17 00:00:00 2001 From: m9n2fglbo Date: Mon, 6 Nov 2023 21:23:19 +0800 Subject: [PATCH] ADD file via upload --- c2.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 c2.c diff --git a/c2.c b/c2.c new file mode 100644 index 0000000..b49208d --- /dev/null +++ b/c2.c @@ -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"); +}