You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.0 KiB
69 lines
1.0 KiB
#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");
|
|
} |