Advertisement
evage

Untitled

Oct 13th, 2021
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n;
  8.     cout << "Enter count of numbers\n";
  9.     cin >> n;
  10.     vector<int> a(n);
  11.     srand(time(NULL));
  12.     for (int i = 0; i < n; ++i)
  13.     {
  14.         a[i] = (rand() % 50) + 1;
  15.     }
  16.     sort(a.begin(), a.end());
  17.     for (int i = 0; i < n; ++i)
  18.         cout << a[i] << ' ';
  19.     cout << '\n';
  20.     int s = 0, cnt = 0;
  21.     for (int i = 0; i < n; ++i)
  22.     {
  23.         if (a[i] % 2 != 0)
  24.             s += a[i];
  25.         if (a[i] > 25)
  26.             ++cnt;
  27.     }
  28.     cout << "sum = " << s << endl;
  29.     cout << "count = " << cnt << endl;
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement