Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Сумма членов после отрицательного #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- int n;
- cout << "Введите количество элементов: "; cin >> n;
- int i, ineg;
- float sum, *a = new float[n];
- cout << "Введите элементы массива: ";
- for (i = 0; i < n; i++) cin >> a[i];
- for (i = 0; i < n; i++) cout << a[i] << " ";
- for (i = 0; i < n; i++) if (a[i] < 0) ineg = i;
- for (sum = 0, i = ineg + 1; i < n; i++) sum += a[i];
- cout << "Сумма - " << sum << endl;
- return 0;
- }
- #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- int n;
- cout << "Введите количество элементов: "; cin >> n;
- int i;
- float *a = new float[n];
- cout << "Введите элементы массива: ";
- for (i = 0; i < n; i++) cin >> a[i];
- bool flag_neg = false;
- float sum = 0;
- for (i = m - 1; i >= 0; i--){
- if (a[i] < 0){ flag_neg = true; break; }
- sum += a[i]
- }
- if (flag_neg) cout << "\nСумма" << sum;
- else cout << "\nОтрицательных элементов нет";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement