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.
97 lines
1.3 KiB
97 lines
1.3 KiB
3 weeks ago
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <time.h>
|
||
|
int main()
|
||
|
{
|
||
|
srand(time(NULL));
|
||
|
int i,j,k,p=0,l;
|
||
|
int temp1,temp2,temp;
|
||
|
int a[9][9]={0},t1[9]={1,2,3,4,5,6,7,8,9},t2[3];
|
||
|
for(i=0;i<9;i++)
|
||
|
{
|
||
|
if(i%3==0)
|
||
|
{
|
||
|
for(j=0;j<10;j++)
|
||
|
{
|
||
|
temp1=rand()%9;
|
||
|
temp2=rand()%9;
|
||
|
if(temp1!=temp2)
|
||
|
{
|
||
|
temp=t1[temp1];
|
||
|
t1[temp1]=t1[temp2];
|
||
|
t1[temp2]=temp;
|
||
|
}
|
||
|
}
|
||
|
l=0;
|
||
|
}
|
||
|
for(j=0;j<3;j++)
|
||
|
{
|
||
|
t2[j]=rand()%9;
|
||
|
for(k=0;k<j;k++)
|
||
|
{
|
||
|
if(t2[j]==t2[k])
|
||
|
{
|
||
|
t2[j]=rand()%9;
|
||
|
}
|
||
|
if(t2[j]==t2[k])
|
||
|
{
|
||
|
t2[j]=rand()%9;
|
||
|
}
|
||
|
if(t2[j]==t2[k])
|
||
|
{
|
||
|
t2[j]=rand()%9;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//printf("%d %d %d\n",t2[0],t2[1],t2[2]);
|
||
|
for(p=0;p<3;p++)
|
||
|
{
|
||
|
a[i][t2[p]]=t1[l];
|
||
|
l++;
|
||
|
}
|
||
|
}
|
||
|
/*for(i=0;i<9;i++)
|
||
|
{
|
||
|
for(j=0;j<9;j++)
|
||
|
{
|
||
|
printf("%d",a[i][j]);
|
||
|
}
|
||
|
printf("\n");
|
||
|
}
|
||
|
*/
|
||
|
printf("|");
|
||
|
for(i=0;i<11;i++)
|
||
|
{
|
||
|
printf("-");
|
||
|
}
|
||
|
printf("|\n");
|
||
|
for(i=0;i<9;i++)
|
||
|
{
|
||
|
printf("|");
|
||
|
for(j=0;j<3;j++)
|
||
|
{
|
||
|
for(k=0;k<3;k++)
|
||
|
{
|
||
|
printf("%d",a[i][j*3+k]);
|
||
|
}
|
||
|
if(j==2){
|
||
|
printf("|\n");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("|");
|
||
|
}
|
||
|
}
|
||
|
if((i%3)==2)
|
||
|
{
|
||
|
printf("|");
|
||
|
for(p=0;p<11;p++)
|
||
|
{
|
||
|
printf("-");
|
||
|
}
|
||
|
printf("|\n");
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|