Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int sizeArray() {
- int n;
- cout << "Введите размер массива: ";
- cin >> n;
- return n;
- }
- void inputArray(int size, int* arr) {
- cout << "Введите элементы массива: \n";
- for (int i = 0; i < size; i++) {
- cout << "arr[" << i << "] = ";
- cin >> *(arr + i);
- }
- }
- void findNegative(int& k, int* arr, int& size, int& count) {
- int i = 0;
- while (k < 0 && i < size) {
- if (arr[i] < 0)
- k = i;
- i++;
- }
- while (count < 0 && i < size) {
- if (arr[i] < 0)
- count = i;
- i++;
- }
- }
- void outputNegative(int k, int count, int* arr) {
- int sum = 0;
- ; if ((k + 1 > count) || (k == count)) {
- cout << "В данном массиве меньше двух отрицательных элементов";
- }
- else {
- cout << "Сумма элементов массива, расположенных между первым и вторым отрицательными элементами: ";
- for (int j = k + 1; j < count; j++) {
- sum += arr[j];
- }
- cout << sum;
- }
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- int n, count = -1, k = -1;
- n = sizeArray();
- int* arr = new int[n];
- inputArray(n, arr);
- findNegative(k, arr, n, count);
- outputNegative(k, count, arr);
- delete[] arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment