Advertisement
SkeptaProgrammer

Untitled

Jun 25th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <ctime>
  5. #include <iomanip>
  6. using namespace std;
  7.  
  8.  
  9. void ChangeRows(double **a, int n, int m)
  10. {
  11.     double* temp;
  12.     for (int i = 0; i < n - 1; i++) {
  13.         for (int j = 0; j < n - i - 1; j++) {
  14.             if (a[j][0] > a[j + 1][0]) {
  15.                 temp = a[j];
  16.                 a[j] = a[j + 1];
  17.                 a[j + 1] = temp;
  18.             }
  19.         }
  20.     }
  21. }
  22.  
  23. int main()
  24. {
  25.     setlocale(0, "");
  26.     srand(time(0));
  27.     double **a, b = 0;
  28.     int i, j, n, m, k;
  29.     cout << "Введите размер n*m" << "\n";
  30.     cin >> n >> m;
  31.     a = new double*[n];
  32.     for (i = 0; i < n; i++)
  33.         a[i] = new double[m];
  34.     for (i = 0; i < n; i++)
  35.         for (j = 0; j < m; j++)
  36.             a[i][j] = rand() % 50 - 24;
  37.     cout << "Матрица:" << endl;
  38.     for (i = 0; i < n; i++)
  39.     {
  40.         for (j = 0; j < m; j++)
  41.             cout << setw(10)<< a[i][j] << "\t";
  42.         cout << endl;
  43.     }
  44.     cout << "введите :" << endl;
  45.     ChangeRows(a, n, m);
  46.     cout << "Результат:" << endl;
  47.     for (i = 0; i < n; i++)
  48.     {
  49.         for (j = 0; j < m; j++)
  50.             cout << setw(10) << a[i][j] << "\t";
  51.         cout << endl;
  52.     }
  53.     for (i = 0; i < n; i++)
  54.         delete[] a[i];
  55.     delete[]a;
  56.     system("pause");
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement