M

This resource is not intended to correct homework. Nevertheless, I'm going to deal with the fundamental errors in detail, and how to apply them to your decision will have to be considered on my own. You didn't come here to get your expertise, did you?1. Use of operator ++Operator ++ is a combined operator that increases the current variable by 1. I draw attention to the fact that this change is not temporary but permanent. Several examples:Simple casex++;
//или
++x;
//эквивалентная запись
x = x + 1;
InputFirst case (increase per unit after use)int x = 1, y = 0;
y = x++;
//эквивалентная запись
y = x;
x = x + 1;
//в результате y=1, x=2
Second case (increase per unit before use)int x = 1, y = 0;
y = ++x;
//эквивалентная запись
x = x + 1;
y = x;
//в результате y=2, x=2
The same applies to the operator. --♪ I don't think it's hard to see the difference. 2. Operator +=It's easier with this operator, I'll just move on to an equivalent record:x += y;
//эквивалент
x = x + y;
//но никак не x = y;
You shouldn't use abbreviations if you don't understand how it works. The downgraded records are intended to reduce the volume of the code of actual large programmes, and in the training programmes, they simply complicate the understanding of the algorithm.Now look at the fragment of your code://первый проход по циклу
for (int j = 0; j < n; j++)
//предполагается, что значение j уведичится после окончания цикла,
//а во время выполнеия будет равно 0
{
if (a[m, j] < a[m, j++])//сравниваем a[m,0] и a[m,0]
//увеличение после использования. после сравнения j = 1
{
//код который был тут никогда не выполнится, т.к. x < x == false
}
//первый проход закочен, цикл увеличивает счестчик на один
//на втором проходе j = 2, а должно быть 1.
}
There's two mistakes. First, never use operators. ++ and -- to the cycle counter for inside the cycle, this disturbs the perishability of the counter values, at least until you're equipped with basic algorithms. And the other is the incorrect use of the generator. ++ attracted to incorrect elements, instead of writing j+1♪Okay. Correct. ifWhat's next?for (int j = 0; j < n; j++)
{
if (a[m, j] < a[m, j+1])
{
x += a[m, j];//вы уверены, что хотите получить в x сумму всех подходящих элементов?
a[m, j] = a[m, j++];//a[m,j] = a[m,j], а смысл?
a[m, j++] = x;//тут вроде бы все хорошо, a[m, j+1] = x,
//только вот значение a[m, j+1] затерлось новым значением
//ну и счетчик цикла, как и в прошлый раз сбился, если в первый раз
//через один, то теперь через два.
}
}
3. Why doesn't it work?Let us begin by saying that the code presented does not contain the algorithm of sorting.Of the simple algorithms of sorting, you were supposed to be told three:- bubbles- selection- boxingThus, for the matrix and expected result, the algorithm must look so (psevdodod)//для каждой строки матрицы
for(int i = 0; i < n i++)
{
//Сортируем строку с индексом i
}
Any of the sorting algorithms listed above can easily be found on its name, including the C# work reference code, so that this will also remain for self-employment.Practical advice: don't be limited to mere copying the found source, figure out how it works and practice on a single-dimensional set, as already recommended in the commentaries. https://ru.stackoverflow.com/users/227049/foggy-finder ♪Then apply the same algorithm to the row of the matrix, the difference will only be that for the two-size area, the row number will be given by an outside cycle variable.