35657

Untitled

Feb 16th, 2024
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7.     // подсчитать сумму всех отрицательных элементов в массиве
  8.  
  9.     setlocale(LC_ALL, "ru");
  10.  
  11.     const int size = 5;
  12.  
  13.     int arr[size]{ -23,11,-5,9,-7 };
  14.  
  15.     int sum = 0;
  16.  
  17.     for (int i = 0; i < size; i++) {
  18.         if (arr[i] < 0) {
  19.             sum += arr[i];
  20.         }
  21.     }
  22.  
  23.     cout << "sum = " << sum << endl;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment