Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <stdlib.h>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int a[i] = {};
- for (int i = 0; i < 3; i++)
- {
- a[i] = rand(); // запись случайного числа, которое вернет rand()
- cout << a[i] << endl;
- }
- /*for (int i = 0; i < n; i++)
- a[i] = (rand() % 20) / (10 * 1.0) - 7 / (10 * 1.0);
- for (int i = 0; i < n; i++)
- cout << a[i] << " ";*/
- int min = 0; int x, numb = 0, fneg, nneg;
- if (a[0] < 0)
- {
- numb++;
- fneg = 0;
- }
- for (int i = 0; i < n; i++)
- {
- if (a[min] > a[i]) min = i;
- if ((a[i] < 0) && numb < 1)
- {
- fneg = i;
- numb++;
- i++;
- }
- if ((a[i] < 0) && numb < 2)
- {
- nneg = i;
- numb++;
- }
- cout << endl;
- int sum = 0;
- for (int i = fneg + 1; i < nneg; i++)
- sum += a[i];
- cout << "1) The number of the minimum element: " << min << endl;
- cout << "2) Sum of array elements located between the first and second negative elements: " << sum << endl;
- delete[]a;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement