Vla_DOS

2

Jul 2nd, 2022
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     setlocale(0, "");
  8.     int n = 0, a = 0, d = 0;
  9.     cout << "Введiть розмiр масиву: ";
  10.     cin >> n;
  11.     int* arr = new int[n];
  12.  
  13.     for (int i = 0; i < n; i++) {
  14.         arr[i] = rand() % 27;
  15.     }
  16.     for (int i = 0; i < n; i++) {
  17.         cout << arr[i] << "\t";
  18.     }
  19.  
  20.     int min = arr[0];
  21.     int max = arr[0];
  22.     for (int i = 0; i < n; i++) {
  23.         if (min > arr[i]) {
  24.             min = arr[i];
  25.         }
  26.  
  27.         if (max < arr[i]) {
  28.             max = arr[i];
  29.         }
  30.     }
  31.  
  32.     cout << "\nСереднє арифметичне: " << (min + max) / 2 << endl;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment