Advertisement
SeriousVenom

Untitled

Dec 16th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main()
  10. {
  11.     int a[i] = {};
  12.  
  13.     for (int i = 0; i < 3; i++)
  14.     {
  15.         a[i] = rand(); // запись случайного числа, которое вернет rand()
  16.         cout << a[i] << endl;
  17.     }
  18.  
  19.  
  20.  
  21.  
  22.     /*for (int i = 0; i < n; i++)
  23.         a[i] = (rand() % 20) / (10 * 1.0) - 7 / (10 * 1.0);
  24.     for (int i = 0; i < n; i++)
  25.         cout << a[i] << " ";*/
  26.  
  27. int min = 0; int x, numb = 0, fneg, nneg;  
  28.  
  29. if (a[0] < 0)
  30. {
  31.     numb++;
  32.     fneg = 0;
  33. }
  34. for (int i = 0; i < n; i++)
  35. {
  36.     if (a[min] > a[i]) min = i;
  37.     if ((a[i] < 0) && numb < 1)
  38.     {
  39.         fneg = i;
  40.         numb++;
  41.         i++;
  42.     }
  43.     if ((a[i] < 0) && numb < 2)
  44.     {
  45.         nneg = i;
  46.         numb++;
  47.     }
  48.     cout << endl;
  49.  
  50.     int sum = 0;
  51.     for (int i = fneg + 1; i < nneg; i++)
  52.         sum += a[i];
  53.  
  54.     cout << "1) The number of the minimum element: " << min << endl;
  55.     cout << "2) Sum of array elements located between the first and second negative elements: " << sum << endl;
  56.  
  57.     delete[]a;
  58.     return 0;
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement