max = a[n][m]; for( i = 0; i < n; i++) { for( j = 0; j < m; j++) { for( k = 0; k < n; k++) { for( l = 0; l < m; l++) { if (a[i][j] == a[k][l]) { if(a[i][j] > max) { max = a[i][j]; break; } } } } } } printf("%d",a[i][j]); 

tell me what's wrong here

  • 2
    is_in_matrix_more_once() . Joke :) Or do you seriously think that there is such a standard function? - Harry
  • No, I ask what algorithm is needed for this) - Sanya
  • 2
    @SanyaAllen. Well, look, if in the matrix under another index there is the same value, then, most likely, it occurs more often than once - Anton M
  • 2
    Well, as an option: write the matrix into a one-dimensional array, sort in descending order and already in this array find duplicates that are conveniently located one behind the other. - RiotBr3aker
  • one
    here "not so" everything, starting with the line max = a[n][m]; - Igor

1 answer 1

One solution:

  1. Take a separate array with zero elements and increase by one the value that is stored by index equal to the value of the element of the original matrix.
  2. Then drop all elements with values ​​less than 2 from the array.
  3. The last remaining array index will be the desired value.