Hello, I have a task that I can not solve, could not help me. Given a square matrix by rearranging rows and columns, arrange the elements of the diagonal in descending order in C #.
Here I wrote the code, but why doesn't it sort the diagonals
static void Main(string[] args) { int buf = 0; int[, ] mass = new int[4, 4]; Random rand = new Random(); for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) mass[i, j] = rand.Next(10); //вывод матрици for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { Console.Write(mass[i, j]); } Console.WriteLine(" "); } for (int i = 0; i < 4; i++) for (int j = 0; j < 3; j++) if (i == j) if (mass[i, j] > mass[i + 1, j + 1]) { // перестановка строк for (int s = 0; s < 1; s++) for (int k = 0; k < 4; k++) { buf = mass[s, k]; mass[s, k] = mass[s + 1, k]; mass[s + 1, k] = buf; } // перестановка столбцов for (int s = 0; s < 4; s++) for (int k = 0; k < 1; k++) { buf = mass[s, k]; mass[s, k] = mass[s, k + 1]; mass[s, k + 1] = buf; } } Console.WriteLine(" "); //вывод for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { Console.Write(mass[i, j]); } Console.WriteLine(" "); } } } }