Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- // подсчитать сумму всех отрицательных элементов в массиве
- setlocale(LC_ALL, "ru");
- const int size = 5;
- int arr[size]{ -23,11,-5,9,-7 };
- int sum = 0;
- for (int i = 0; i < size; i++) {
- if (arr[i] < 0) {
- sum += arr[i];
- }
- }
- cout << "sum = " << sum << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment