parent
15dc9becad
commit
b7d885f413
@ -0,0 +1,55 @@
|
||||
#include<stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
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");
|
||||
}
|
Loading…
Reference in new issue