Advertisement
VictoriaLodochkina

lab 10 z1 probnii

Dec 13th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. //НУЖНО ПРОВЕРИТЬ ЭТУ ДИЧЬ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2. #include "pch.h"
  3. #include <iostream>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. void sortmas(int k, int l, double *mas1, int s);
  9.  
  10. int main()
  11. {
  12.     int n;
  13.     cin >> n;
  14.     cout << "Enter n: " << endl;
  15.     double *mas = new double[n];
  16.     cout << "Enter mas: " << endl;
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         cin >> mas[i];
  20.     }
  21.     double max = mas[0];
  22.     double min = mas[0];
  23.     int imin, imax;
  24.     for (int i = 0; i < n; i++)
  25.     {
  26.         if (fabs(mas[i]) >= max)
  27.         {
  28.             max = mas[i];
  29.             imax = i;
  30.         }
  31.         if (fabs(mas[i]) <= min)
  32.         {
  33.             min = mas[i];
  34.             imin = i;
  35.         }
  36.     }
  37.     sortmas(imin, imax, mas, n);
  38.     return 0;
  39. }
  40.  
  41. void sortmas(int k, int l, double *mas1, int s)
  42. {
  43.     int b = 0;
  44.     for (int i = k; i <= l - 3; i++)
  45.     {
  46.         for (int j = k + 1; j <= l - 2 - b; j++)
  47.             if (mas1[j] < mas1[j + 1])
  48.             {
  49.                 int t = mas1[j];
  50.                 mas1[j] = mas1[j + 1];
  51.                 mas1[j + 1] = t;
  52.             }
  53.         b++;
  54.     }
  55.     for (int i = 0; i < s; i++)
  56.     {
  57.         cout << mas1[i];
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement