Advertisement
VictoriaLodochkina

lab10 z1 vrode tak

Dec 20th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 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. int imin(int s, double *mas1);
  10. int imax(int s, double *mas1);
  11.  
  12. int main()
  13. {
  14.     int n;
  15.     cout << "Enter n: " << endl;
  16.     cin >> n;
  17.     double *mas = new double[n];
  18.     cout << "Enter mas: " << endl;
  19.     for (int i = 0; i < n; i++)
  20.     {
  21.         cin >> mas[i];
  22.     }
  23.     double max = mas[0];
  24.     double min = mas[0];
  25.     int low, high;
  26.     /*for (int i = 0; i < n; i++)
  27.     {
  28.         if (fabs(mas[i]) >= max)
  29.         {
  30.             max = mas[i];
  31.             imax = i;
  32.         }
  33.         if (fabs(mas[i]) <= min)
  34.         {
  35.             min = mas[i];
  36.             imin = i;
  37.         }
  38.     }*/
  39.     low=imin(n, mas);
  40.     high = imax(n, mas);
  41.     sortmas(low, high, mas, n);
  42.     return 0;
  43. }
  44.  
  45. void sortmas(int k, int l, double *mas1, int s)
  46. {
  47.     int b = 0;
  48.     for (int i = k; i <= l - 3; i++)
  49.     {
  50.         for (int j = k + 1; j <= l - 2 - b; j++)
  51.             if (mas1[j] < mas1[j + 1])
  52.             {
  53.                 int t = mas1[j];
  54.                 mas1[j] = mas1[j + 1];
  55.                 mas1[j + 1] = t;
  56.             }
  57.         b++;
  58.     }
  59.     for (int i = 0; i < s; i++)
  60.     {
  61.         cout << mas1[i];
  62.     }
  63. }
  64. int imin(int s, double *mas1)
  65. {
  66.     int minx = -1;
  67.     double min = mas1[0];
  68.     for (int i = 0; i < s; i++)
  69.     {
  70.         if (fabs(mas1[i]) <= min)
  71.         {
  72.             min = mas1[i];
  73.             minx = i;
  74.         }
  75.     }
  76.     return minx;
  77. }
  78. int imax(int s, double *mas1)
  79. {
  80.     int maxx = -1;
  81.     double max = mas1[0];
  82.     for (int i = 0; i < s; i++)
  83.     {
  84.         if (fabs(mas1[i]) >= max)
  85.         {
  86.             max = mas1[i];
  87.             maxx = i;
  88.         }
  89.     }
  90.     return maxx;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement