Advertisement
GarikK

arrays(max-min,diapazon,proizvedenie)

Feb 26th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. // array!.cpp :
  2. //
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.     float sum = 0;
  11.     int max = 0;
  12.     int min = 10000;
  13.     int multi = 1;
  14.     int multi2 = 1;
  15.     int sumBetweenNegative = 0;
  16.     int arraySize;
  17.     int array[10000];
  18.     cout << "Please enter array size by one number " << endl;
  19.     cin >> arraySize;
  20.     array[1000] = arraySize;
  21.     cout << "Please enter random negative numbers " << endl;
  22.     // найти сумму отрицательных чисел
  23.     for (int i = 0; i < arraySize; i++)
  24.     {
  25.         cin >> array[i];
  26.     }
  27.     for (int i = 0; i < arraySize; i++)
  28.     {
  29.         if (array[i] < 0) sum += array[i];
  30.     }
  31.     cout << "This is the sum " << sum << endl << endl;
  32.  
  33.     //найти произведение диапазона от минимального к максимальному числу
  34.     cout << "Let\'s find the product form min to max diapazon\n enter numbers please" << endl;
  35.     for (int i = 0; i < arraySize; i++)
  36.     {
  37.         cin >> array[i];   
  38.     }
  39.  
  40.     for (int i = 0; i < arraySize; i++)
  41.     {
  42.         if (max < array[i]) max = array[i];
  43.         if (array[i] < min) min = array[i];
  44.     }
  45.     cout << "This is max = " << max << endl;
  46.     cout << "This is min = " << min << endl << endl;
  47.  
  48.     for (int i = min; i < max; i++)
  49.     {
  50.         multi *= array[i];
  51.        
  52.     }
  53.     cout << "This is product " << multi << endl;
  54.  
  55.     //произведение элементов с четными номерами
  56.     for (int i = 0; i < arraySize; i++)
  57.     {
  58.         if (array[i] % 2 == 0)
  59.         {
  60.             multi2 *= array[i];
  61.         }
  62.     }
  63.     cout << "This is multi of the parity numbers " << multi2 << endl << endl << endl;
  64.  
  65.     //сумма между отрицательными элементами
  66.     int minus = 0;
  67.     int minus2 = 0;
  68.     cout << "Let\'s find the sum from the first minus number to the last minus number\nplease enter the array size and then the numbers" << endl;
  69.     cin >> arraySize;
  70.     array[1000] = arraySize;
  71.     for (int i = 0; i < arraySize; i++)
  72.     {
  73.         cin >> array[i];
  74.     }
  75.     int k = 0, p = 0;
  76.     for (int i = 0; i < arraySize; i++)
  77.     {
  78.         if (array[i] < 0)
  79.         {
  80.             minus2 = array[i];
  81.             p = i;
  82.         }
  83.     }
  84.     for (int i = arraySize; i > 0; i--)
  85.     {
  86.         if (array[i] < 0)
  87.         {
  88.             minus = array[i];
  89.             k = i;
  90.         }
  91.     }
  92.     for (int i = k + 1; i < p; i++)
  93.     {
  94.         sumBetweenNegative += array[i];
  95.        
  96.     }
  97.  
  98.     cout << "This is sum between negative " << sumBetweenNegative;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement