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.
60 lines
857 B
60 lines
857 B
2 weeks ago
|
#include<stdio.h>
|
||
|
#include <time.h>
|
||
|
#include <stdlib.h>
|
||
|
void x1(int m[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",m[i][j]);
|
||
|
}
|
||
|
printf("|\n");
|
||
|
}
|
||
|
printf("-------------");
|
||
|
}
|
||
|
void x2(int m[9][9])
|
||
|
{
|
||
|
|
||
|
int i,j,b,c,d;
|
||
|
int e[9];
|
||
|
for(i=0;i<9;i++)
|
||
|
{
|
||
|
int k[9]={1,2,3,4,5,6,7,8,9};
|
||
|
int q[9]={0};
|
||
|
int l[9]={0};
|
||
|
int p[9]={0};
|
||
|
for(b=0;b<3;b++)
|
||
|
{
|
||
|
int t;
|
||
|
do{
|
||
|
t=rand()%9;
|
||
|
}while(q[k[t]-1]||l[t]);
|
||
|
p[b*3+rand()%3]=t+1;
|
||
|
q[k[t]-1]=1;
|
||
|
l[t]=1;
|
||
|
}
|
||
|
for (c = 0; c < 9; c++) {
|
||
|
if (p[c] == 0) {
|
||
|
p[c] = 0;
|
||
|
}
|
||
|
}
|
||
|
for(d=0;d<9;d++)
|
||
|
{
|
||
|
m[i][d]=p[d];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
int main()
|
||
|
{
|
||
|
srand(time(NULL));
|
||
|
int m[9][9]={0};
|
||
|
x2(m);
|
||
|
x1(m);
|
||
|
return 0;
|
||
|
}
|
||
|
|