Advertisement
themlgyo

блядскийсука

Oct 5th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. Сумма членов после отрицательного #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     setlocale(LC_ALL, "RUSSIAN");
  6.     int n;
  7.     cout << "Введите количество элементов: "; cin >> n;
  8.     int i, ineg;
  9.     float sum, *a = new float[n];
  10.     cout << "Введите элементы массива: ";
  11.     for (i = 0; i < n; i++) cin >> a[i];
  12.     for (i = 0; i < n; i++) cout << a[i] << " ";
  13.     for (i = 0; i < n; i++) if (a[i] < 0) ineg = i;
  14.     for (sum = 0, i = ineg + 1; i < n; i++) sum += a[i];
  15.     cout << "Сумма - " << sum << endl;
  16.     return 0;
  17. }
  18.  
  19. #include <iostream>
  20. using namespace std;
  21. int main()
  22. {
  23.     setlocale(LC_ALL, "RUSSIAN");
  24.     int n;
  25.     cout << "Введите количество элементов: "; cin >> n;
  26.     int i;
  27.     float *a = new float[n];
  28.     cout << "Введите элементы массива: ";
  29.     for (i = 0; i < n; i++) cin >> a[i];
  30.     bool flag_neg = false;
  31.     float sum = 0;
  32.     for (i = m - 1; i >= 0; i--){
  33.         if (a[i] < 0){ flag_neg = true; break; }
  34.         sum += a[i]
  35.     }
  36.     if (flag_neg) cout << "\nСумма" << sum;
  37.     else cout << "\nОтрицательных элементов нет";
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement