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.
77 lines
1.8 KiB
77 lines
1.8 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include <time.h>
|
|
|
|
int** boradgenerate() {
|
|
int count_col = 0;
|
|
int count_row = 0;
|
|
int col[3] = { 0 };
|
|
int col_true[9] = { 0 };
|
|
int** borad;
|
|
borad = (int**)malloc(9 * sizeof(int*));
|
|
for (int i = 0; i < 9; i++)
|
|
borad[i] = (int*)malloc(9 * sizeof(int));
|
|
|
|
for (count_row = 0; count_row <= 8; count_row++) {
|
|
while (count_col != 3)
|
|
{
|
|
int num = rand() % 9;
|
|
if (col_true[num] == 0) {
|
|
col[count_col++] = num;
|
|
col_true[num] = 1;
|
|
}
|
|
}
|
|
count_col = 0;
|
|
for (int i = 0; i < 9; i++)
|
|
{
|
|
col_true[i] = 0;
|
|
}
|
|
while (count_col != 3)
|
|
{
|
|
borad[count_row][col[count_col++]] = rand() % 9 + 1;
|
|
}
|
|
count_col = 0;
|
|
}
|
|
return borad;
|
|
}
|
|
|
|
void boradprint(int** board) {
|
|
printf("|-----------------------|\n");
|
|
for (int row = 0; row < 9; row++) {
|
|
if (row == 3 || row == 6) {
|
|
printf("|-----------------------|\n");
|
|
}
|
|
printf("| ");
|
|
for (int col = 0; col < 9; col++) {
|
|
if (board[row][col] == 0) {
|
|
printf(". ");
|
|
}
|
|
else {
|
|
printf("%d ", board[row][col]);
|
|
}
|
|
if (col == 2 || col == 5) {
|
|
printf("| ");
|
|
}
|
|
}
|
|
printf("|\n");
|
|
}
|
|
printf("|-----------------------|\n");
|
|
}
|
|
|
|
int main() {
|
|
int board[9][9] = { {5,3,4,6,7,8,9,1,2},
|
|
{6,7,2,1,9,5,3,4,8},
|
|
{1,9,8,3,4,2,5,6,7},
|
|
{8,5,9,7,6,1,4,2,3},
|
|
{4,2,6,8,5,3,7,9,1},
|
|
{7,1,3,9,2,4,8,5,6},
|
|
{9,6,1,5,3,7,2,8,4},
|
|
{2,8,7,4,1,9,6,3,5},
|
|
{3,4,5,2,8,6,1,7,9} };
|
|
srand(time(NULL));
|
|
boradprint(board);
|
|
|
|
return 0;
|
|
}
|