Well I'm doing a college job which is to make a sudoku in which the PC plays, first I'm creating the rules of the game which is no number can be repeated on the line nor in the row where it is .. .
As everyone knows sudoku starts with some numbers so I put them using srand + rand ()% x and some numbers end up repeating themselves ...
Another problem I am having is with the other space I would like to know what I do so nothing appears ... I put NULL and as I am using integers the number 0 appears.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int su[9][9];
int i, j;
int cont;
srand( (unsigned)time(NULL) );//evita que o rand seja gerado pelo tempo
for(i=0; i<9; i++)
{
for(j=0; j<9; j++)
{
cont=rand()%9;
if(i==cont || j==cont)
su[i][j]=1+rand()%9;
else
{
su[i][j]=NULL;
}
if( su[i][j]==su[i+1][j+1])
{
su[i][j]=NULL;
}
}
}
for(i=0; i<9; i++)
{
for(j=0; j<9; j++)
{
printf("[%i]", su[i][j]);
}
printf("\n");
}
/*for(i=1 ; i <= 10 ; i++)
printf("Numero %d: %d\n",i, 1+rand()%9);*/
return 0;
}