CyberN00b

Untitled

Jan 11th, 2022 (edited)
383
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 <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a;
  8.     cin >> a;
  9.     vector<int> vc(a);
  10.     for (int i = 0; i < a; ++i)
  11.         cin >> vc[i];
  12.     for (int i = 0; i < a; ++i)
  13.         for (int j = i + 1; j < a; ++j)
  14.             if (abs(vc[i]) > abs(vc[j]))
  15.                 swap(vc[i], vc[j]);
  16.     cout << "Отсортированный массив модулей:\n";
  17.     for (int i = 0; i < a; ++i)
  18.         cout << vc[i] << ' ';
  19.     int sum = 0, pro = 1;
  20.     for (int i = 0; i < a; ++i)
  21.         if (vc[i] > 0) {
  22.             sum += vc[i];
  23.             pro *= vc[i];
  24.         }
  25.     cout << "\nсумма: " << sum << "\nпроизведение: " << pro;
  26. }
Add Comment
Please, Sign In to add comment