This code does not show how the largest element in the array should be positioned correctly. What is the error?
#include <stdio.h>
#include <stdlib.h>
#define lin 4
#define col 4
int main()
{
int mat[lin][col], i, j, maior=mat[0][0], pos_i, pos_j;
printf("Informe os elementos da matriz\n");
for(i=0;i<lin;i++){
for(j=0;j<col;j++){
printf("[%d][%d] = ", i,j);
scanf("%d", &mat[i][j]);
if(mat[i][j] > maior) {
maior=mat[i][j];
pos_i=i;
pos_j=j;
}
}
}
printf("O maior elemento da matriz: %d\n", maior);
printf("Posicao: [%d][%d]\n", pos_i,pos_j);
return 0;
}
So it displays: For smaller array value it displays correctly, but for larger no.