Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main()
- {
- int a;
- cin >> a;
- vector<int> vc(a);
- for (int i = 0; i < a; ++i)
- cin >> vc[i];
- for (int i = 0; i < a; ++i)
- for (int j = i + 1; j < a; ++j)
- if (abs(vc[i]) > abs(vc[j]))
- swap(vc[i], vc[j]);
- cout << "Отсортированный массив модулей:\n";
- for (int i = 0; i < a; ++i)
- cout << vc[i] << ' ';
- int sum = 0, pro = 1;
- for (int i = 0; i < a; ++i)
- if (vc[i] > 0) {
- sum += vc[i];
- pro *= vc[i];
- }
- cout << "\nсумма: " << sum << "\nпроизведение: " << pro;
- }
Add Comment
Please, Sign In to add comment