parent
eb1a1046c4
commit
7af5ba3d6d
@ -0,0 +1,69 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
int main()
|
||||
{
|
||||
int board[9][9]={{0}};
|
||||
srand(time(NULL));
|
||||
int temp1;
|
||||
int temp2;
|
||||
int temp3;
|
||||
int temp4;
|
||||
int temp5;
|
||||
int temp6;
|
||||
int x[9]={0};
|
||||
int a=0;
|
||||
while(a<9)
|
||||
{
|
||||
temp1=rand()%3;
|
||||
temp2=rand()%9;
|
||||
if(board[temp1][temp2]==0&&x[temp1]<3)
|
||||
{
|
||||
board[temp1][temp2]=a+1;
|
||||
x[temp1]=x[temp1]+1;
|
||||
a++;
|
||||
}
|
||||
}
|
||||
a=0;
|
||||
while(a<9)
|
||||
{
|
||||
temp3=rand()%3+3;
|
||||
temp4=rand()%9;
|
||||
if(board[temp3][temp4]==0&&x[temp3]<3)
|
||||
{
|
||||
board[temp3][temp4]=a+1;
|
||||
x[temp3]=x[temp3]+1;
|
||||
a++;
|
||||
}
|
||||
}
|
||||
a=0;
|
||||
while(a<9)
|
||||
{
|
||||
temp5=rand()%3+6;
|
||||
temp6=rand()%9;
|
||||
if(board[temp5][temp6]==0&&x[temp5]<3)
|
||||
{
|
||||
board[temp5][temp6]=a+1;
|
||||
x[temp5]=x[temp5]+1;
|
||||
a++;
|
||||
}
|
||||
}
|
||||
int i,j;
|
||||
for(i=0;i<9;i++)
|
||||
{
|
||||
if (i%3==0)
|
||||
{
|
||||
printf("|-----------|\n");
|
||||
}
|
||||
for(j = 0; j < 9; j++)
|
||||
{
|
||||
if (j % 3 == 0)
|
||||
{
|
||||
printf("|");
|
||||
}
|
||||
printf("%d", board[i][j]);
|
||||
}
|
||||
printf("|\n");
|
||||
}
|
||||
printf("|-----------|\n");
|
||||
}
|
Loading…
Reference in new issue