Statement:
Read a 5x5 matrix. Also read an X value. The program should do a search of this value in the matrix and, at the end, write the location (row and column) or "not found" message
Code:
#include <stdbool.h>
#include <stdio.h>
#define TAM 5
int main(){
int matriz[TAM][TAM], c, c2, num, p1, p2;
bool aux;
for (c=0; c<TAM; c++){
for (c2=0; c2<TAM; c2++){
scanf("%d", &matriz[c][c2]);
}
}
printf("Que numero deseja encontrar? ");
scanf("%d", &num);
for (c=0; c<TAM; c++){
aux = false;
for (c2=0; c2<TAM; c2++){
if (matriz[c][c2] == num){
p1 = c;
p2 = c2;
aux = true;
break;
}
}
}
if (aux){
printf("[%d][%d]", p1, p2);
} else {
printf("Numero nao encontrado. ");
}
return 0;
}
And the problem is this, when I put to find a value that is at the beginning of the array it does not find, just the end.
Can anyone explain why this happens?