Print position of a matrix

Asked

Viewed 2,270 times

1

The intention in this program would be to print the position linha and coluna where the highest value is located within the matrix, someone can tell me why the result is printing 0x0 and if there is another way more effective? In my test of course, the higher value typed was not the first.

#include<stdio.h>
#include<stdlib.h>

int matriz[3][3],i,j,maior=0,i1,j1;

main(){
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            printf("Digite um valor: ");
            scanf("%d",&maior);
            if(matriz[i][j]>maior){
                maior=matriz[i][j];
                i1=i;
                j1=j;
            }//fim if
        }//fim for j
    }//fim for i
    printf("%d x %d \n",i1,j1);
    system("pause");
}//fim do main
  • 1

    Your matrix is not initialized anywhere.

1 answer

1


Change:

scanf("%d",&maior);

To:

scanf("%d",&matriz[i][j]);

You are not reading the correct value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.