S
S
Semyon2020-06-08 00:27:21
C++ / C#
Semyon, 2020-06-08 00:27:21

Sorting elements of a two-dimensional array - how to do it?


spoiler
int K = Convert.ToInt32(numericUpDown1.Value); //получение размера матрицы
            int[,] A = new int[K, K]; //создание матрицы
            Grid.RowCount = K;
            Grid.ColumnCount = K;
            Random rnd = new Random();
                for (int i = 0; i < K; i++) // заполнение матрицы с выводом в dataGridView
                {                          
                for (int j = 0; j < K; j++)
                {
                    A[i, j] = rnd.Next(-100, 100);
                    Grid[j, i].Value = A[i, j];
                    if (i >= j && i + j <= K - 1)// проверка  условия, что это правый треугольник
                    {
                      //... как выполнить условие, что более двух 0 0 и максимальный элемент ?
                    }
                }
                label1.Text = " mах1..";
                }
            for (int i = 0; i < K; i++)// заполнение матрицы с выводом в dataGridView
            { for (int j = 0; j < K; j++)
                {
                    A[i, j] = rnd.Next(-100, 100);
                    Grid[j, i].Value = A[i, j];
                    if (i <= j && i + j > K - 1) // проверка  условия, что это левый треугольник
                    {
                        //... как выполнить условие, что более двух 0 0 и максимальный элемент ?
                    }
                }
                label2.Text = " max2.. ";
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
qwertyk06, 2020-06-08
@qwertyk06

I would divide the task into 2 parts:
1st. Checking the element for the presence of 2 zeros in the entry.
2nd. If the 1st yes, then stupidly search for the maximum.
The second part is not a problem at all.
In C, I’m bad at cutting, so choose for yourself that it’s easier to translate the number into text form and look for 1 character “0” there first, if it is found, delete it, and then look for the second character “0”, then n2.
Or it's stupid to check the remainder of division by 10, if 0, then the number of zeros +1 until the integer from division is not 0 or the number of 0 is less than 2
At the end, check the number of zeros, if 2, see p2.
Although if I understand correctly A[i, j] = rnd.Next(-100, 100) (this is random from -100 to 100) then you just need to check the numbers for equality -100 and 100, other numbers in this range with 2 there are simply no zeros =).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question