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.

95 lines
1.2 KiB

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void copy(int *a,int *b)
{
int i;
for(i=0;i<9;i++)
{
*(a+i)=*(b+i);
}
}
void print(int board[9][9])
{
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]);
if(j==8)
{
printf("|");
}
}
printf("\n");
}
printf("|-----------|\n");
}
void make(int a[9][9])
{
srand(time(NULL));
int b[9]={0};
int c[9];//<2F>ݴ<EFBFBD>
int i,j,k=0,l=0;
int t;
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
copy(c,b);
t=rand()%10;
if(t==0)
{
a[i][j]=t;
}
else
{
if(b[t-1]==0)
{
a[i][j]=t;
b[t-1]=1;
k++;
}
else
{
a[i][j]=0;
}
}
if(k==4)
{
k=0;
for(;j<9;j++)
{
a[i][j]=0;
}
l++;
break;
}
}
if(i%3==2)
{
for(j=0;j<9;j++)
{
b[j]=0;
}
}
}
}
int main()
{
int a[9][9];
make(a);
print(a);
return 0;
}