x2311

Untitled

May 2nd, 2022
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. //порядок m× n
  5. const int M = 6;
  6. const int N = 6;
  7.  
  8. int main() {
  9.     int arr[M][N]{ // матриця дійсних чисел
  10.             {9, 3,  9, 5,  7,  17},
  11.             {1, 3,  4, 65, 9,  48},
  12.             {444, 32, 4, 0,  6,  96},
  13.             {7, 77,  4, 5,  53, 0},
  14.             {0, 3,  4, 5,  73, 14},
  15.             {1, 3,  4, 5,  74, 9},
  16.     };
  17.     //Упорядкувати рядки матриці за не
  18.     //зростанням максимальних елементів рядків.
  19.     for (int i = 0; i < N; i++) {
  20.         for(int k=N;k>0;k--){
  21.             for (int j = 0; j < M - 1; j++) {
  22.                 if (arr[i][j] > arr[i][j + 1]){
  23.                     int a = arr[i][j];
  24.                     arr[i][j] = arr[i][j + 1];
  25.                     arr[i][j + 1] = a;
  26.                 }
  27.             }
  28.         }
  29.  
  30.     }
  31.  
  32.     //результат
  33.     for (int i = 0; i < N; i++) {
  34.         cout << arr[i][0]<< " ";
  35.         for (int j = 0; j < M - 1; j++) {
  36.             cout << arr[i][j+1]<< " ";
  37.         }
  38.         cout << endl;
  39.     }
  40. }
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment