0
I am not able to find the error of this code. I did it to check if in a 4x4 matrix the number being inserted already exists. For some reason that I do not know he accepts the times repeated values and sometimes not...
int main()
{
bool bExit = false;
int iMat[4][4], i = 0, j = 0, ii = 0, jj = 0, iValue = 0;
setlocale(LC_ALL, "Portuguese");
printf("Digite 16 números diferentes para completar a matriz 4x4: \n");
//Recebendo os valores da matriz...
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
printf("%i%i -> ", i, j);
if(i!=0 || j!=0)
{
//Verificando se são repetidos antes de salvar...
do{
scanf("%i", &iMat[i][j]);
for(ii=0; ii<i; ii++)
{
for(jj=0; jj<j; jj++)
{
if((iMat[i][j]) == (iMat[ii][jj]))
{
printf("\nNúmero repetido, digite outro: \n");
printf("%i%i -> ", i, j);
ii = 5;
jj = 5;
bExit = true;
}else{
bExit = false;
}
}
}
}while(bExit);
}else{
scanf("%i", &iMat[i][j]);
}
}
}
//Imprimindo a matriz...
printf("\n");
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
printf("%i ", iMat[i][j]);
}
printf("\n");
}
return 0;
}
Has already drawn up a Table test of your program?
– Woss
Yes... I just discovered that it is not entering the for(ii=0; ii<i; ii++), actually sometimes it enters, sometimes not... Now I’m trying to understand this hahaha
– Ronin F. Matsumoto