S
S
Steve2019-04-09 23:57:52
C++ / C#
Steve, 2019-04-09 23:57:52

How to print the 5 largest elements of a matrix with their indices?

Display the 5 largest elements of the matrix with their indices, but I don’t know how to implement it, at least the idea

for (int i = 0; i < 5; ++i)
    {
        int temp_max_value = 0;
        for (int j = 0; j < row; ++j)
        {
            for (int k = 0; k < column; ++k)
            {
                if(matrix[j][k] > temp_max_value)
                {
                    temp_max_value = matrix[j][k];
                }
            }
        }
        printf("Max value %d\n", temp_max_value);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ronald McDonald, 2019-04-10
Gorton

Idea: find the largest number of each line, drive them into a separate array, sort in ascending order and take the five extreme numbers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question