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.
65 lines
1.1 KiB
65 lines
1.1 KiB
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<time.h>
|
|
int a[10][10]={0};
|
|
int number=0;
|
|
void randomquene(int array[], int len)
|
|
{
|
|
srand(time(NULL));
|
|
for (int i=len-1;i>0;i--)
|
|
{
|
|
int j=rand()%(i+1);
|
|
int temp=array[i];
|
|
array[i]=array[j];
|
|
array[j]=temp;
|
|
}
|
|
}
|
|
void randomputs(int array[],int len)
|
|
{
|
|
for(int row=1;row<10;row++)
|
|
{
|
|
int k=1;
|
|
while(k<4)
|
|
{
|
|
int col=rand()%9+1;
|
|
if(a[row][col]==0)
|
|
{
|
|
a[row][col]=array[number];
|
|
number++;
|
|
k++;
|
|
}
|
|
}
|
|
if(row%3==0)
|
|
{
|
|
number=0;
|
|
randomquene(array,len);
|
|
}
|
|
}
|
|
}
|
|
void format(int s[][10])
|
|
{
|
|
printf("-------------------------\n");
|
|
for(int i=1;i<10;i++)
|
|
{
|
|
printf("| ");
|
|
for(int j=1;j<10;j++)
|
|
{
|
|
|
|
printf("%d ",s[i][j]);
|
|
if(j%3==0) printf("| ");
|
|
}
|
|
printf("\n");
|
|
if(i%3==0) printf("-------------------------\n");
|
|
}
|
|
}
|
|
int main()
|
|
{
|
|
int array[]={1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
int len=sizeof(array)/sizeof(array[0]);
|
|
randomquene(array,len);
|
|
randomputs(array,len);
|
|
format(a);
|
|
return 0;
|
|
}
|
|
|