SeriousVenom

Untitled

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