Advertisement
sneyzi

lab9-task1-12

Jun 8th, 2021
1,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <iomanip>
  5. using namespace std;
  6. int main(int argc, char* argv[])
  7. {
  8.     int n;
  9.  
  10.     double min;
  11.     double max;
  12.  
  13.     cout << "Vvedit kilkist elementiv massiva";
  14.     cin >> n;
  15.     float* ptrarray = new float[n];
  16.     for (int count = 0; count < n; count++) {
  17.         ptrarray[count] = (rand() % 10 + 1) / float((rand() % 10 + 1));
  18.  
  19.     }
  20.  
  21.     min = ptrarray[0];
  22.     max = ptrarray[0];
  23.  
  24.     cout << "array = ";
  25.     for (int count = 0; count < n; count++) {
  26.         if (min > ptrarray[count]) {
  27.             min = ptrarray[count];
  28.         }
  29.  
  30.         if (max < ptrarray[count]) {
  31.             max = ptrarray[count];
  32.         }
  33.  
  34.         if (ptrarray[count] > min * 1.5 && ptrarray[count] < max * 0.5) {
  35.             cout << setprecision(2) << ptrarray[count] << " ";
  36.         }
  37.     }
  38.     cout << endl << "min " << min << " max " << max << endl;
  39.     delete[] ptrarray;
  40.     cout << endl;
  41.     system("pause");
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement