3
Well I am doing a college job which is to do a sudoku in which the PC plays, first I am creating the rules of the game which is no number can be repeated in the row nor in the row where it is...
As you all know sudoku starts with some numbers so I put them using the srand+Rand()%x and some numbers end up repeating themselves...
Another problem I’m having is with the other space I’d like to know what I do to not appear anything... I put NULL and there as I am using integers appears the number 0.
#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;
}
Try to separate the text better, it is difficult to read and understand the problem. The title does not briefly describe the problem. Maybe because you have more than one problem with the question.
– Maniero
I edited your question, as @bigown said, separated the text and put a title that describes the problem. Next time you’ll know what to do. Feel free to edit your question if you feel pertinent.
– Jorge B.