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.
44 lines
732 B
44 lines
732 B
int scan(int matrix[9][9], int r)
|
|
{
|
|
int num = 0;
|
|
for (int i = 0;i < 9;i++)
|
|
{
|
|
if (matrix[r][i] != 0)num++;
|
|
}
|
|
return num;
|
|
}
|
|
void ran0(int matrix[9][9],int n)
|
|
{
|
|
int count = 0;
|
|
int r, j, num;
|
|
while (count < 9)
|
|
{
|
|
do
|
|
{
|
|
r = rand() % 3;
|
|
num = scan(matrix, r + n);
|
|
} while (num >= 3);
|
|
do
|
|
{
|
|
j = rand() % 9;
|
|
} while (matrix[r+n][j] != 0);
|
|
matrix[r + n][j] = ++count;
|
|
}
|
|
}
|
|
void ran(int matrix[9][9])
|
|
{
|
|
ran0(matrix, 0);
|
|
ran0(matrix, 3);
|
|
ran0(matrix, 6);
|
|
}
|
|
int main()
|
|
{
|
|
srand(time(NULL));
|
|
int matrix[9][9] = { 0 };
|
|
ran(matrix);
|
|
mat(matrix);
|
|
system("pause");
|
|
return 0;
|
|
}
|
|
|