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.

56 lines
1.1 KiB

#include<stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int board[9][9]={{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}};
int flag[9][9]={{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}};
srand(time(NULL));
int i,j,p,num;
for(i=0;i<9;i++)
{
for(j=0;j<3;j++)
{
do{
p=rand()%10;
}while(p>=9 || board[i][p]!=0);
do{
num=rand()%10;
}while(num==0 || flag[i][num]==1);
board[i][p]=num;
flag[i][num]=1;
}
}
for(i=0;i<9;i++)
{
if(i%3==0) printf("|-----------------------|\n");
for(j=0;j<9;j++)
{
if(j%3==0) printf(j==0?"|":" |");
printf(" %d",board[i][j]);
}
printf(" |\n");
}
printf("|-----------------------|\n");
}