Advertisement
cacodemon665

Лаба 5 Вариант 7

Dec 19th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     double **mat;
  10.     int n, m;
  11.     cin >> n >> m;
  12.  
  13.     mat = new double*[n];
  14.  
  15.     for (int i = 0; i < n; i++)
  16.     {
  17.         mat[i] = new double[m];
  18.  
  19.         for (int j = 0; j < m; j++)
  20.         {
  21.             cin >> mat[i][j];
  22.         }
  23.     }
  24.    
  25.     for (int i = m - 1; i >= 0; i--)
  26.     {
  27.         for (int j = 0; j < i; j++)
  28.         {
  29.             if (mat[j][0] > mat[j + 1][0])
  30.             {
  31.                 double * temp = mat[j];
  32.                 mat[j] = mat[j + 1];
  33.                 mat[j + 1] = temp;
  34.             }
  35.         }
  36.     }
  37.  
  38.     cout << endl;
  39.  
  40.     for (int i = 0; i < n; i++)
  41.     {
  42.         for (int j = 0; j < m; j++)
  43.         {
  44.             cout << mat[i][j] << " ";
  45.         }
  46.  
  47.         cout << endl;
  48.     }
  49.  
  50.  
  51.     for (int i = 0; i < n; i++)
  52.         delete[] mat[i];
  53.  
  54.     delete[] mat;
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement