Advertisement
Spocoman

01. Fun Sequence

Nov 22nd, 2023
1,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int arrLen, sumNumbers = 0, averageNum;
  8.     cin >> arrLen;
  9.  
  10.     int* numbers = new int[arrLen];
  11.  
  12.     for (size_t i = 0; i < arrLen; i++) {
  13.         cin >> numbers[i];
  14.         sumNumbers += numbers[i];
  15.     }
  16.  
  17.     sort(numbers, numbers + arrLen, greater<int>());
  18.     averageNum = (double)sumNumbers / arrLen;
  19.  
  20.     if (numbers[arrLen - 1] >= averageNum) {
  21.         cout << "No";
  22.     }
  23.     else {
  24.         for (size_t i = 0; i < arrLen; i++) {
  25.             if (numbers[i] < averageNum && numbers[i] % 2 == 0) {
  26.                 cout << numbers[i] << ' ';
  27.             }
  28.         }
  29.     }
  30.     cout << endl;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement