Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

AmidamaruZXC Apr 10th, 2020 138 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // Пункт билета #1
  6. void CreateArray(double* arr, int size)
  7. {
  8.     for (int i = 0; i < size; i++)
  9.         arr[i] = pow(-1, i) * 2 * i / (i + 1);
  10. }
  11.  
  12. // Пункт билета #2
  13. double GetPositiveSum(double* arr, int& index, double& maxValue)
  14. {
  15.     double sum = 0;
  16.     index = 0;
  17.     maxValue = arr[0];
  18.     int size = _msize(arr) / sizeof(double);
  19.     for (int i = 0; i < size; i++)
  20.     {
  21.         if (arr[i] > 0)
  22.             sum += arr[i];
  23.         if (arr[i] > maxValue)
  24.         {
  25.             maxValue = arr[i];
  26.             index = i;
  27.         }
  28.     }
  29.     return sum;
  30. }
  31.  
  32. // Пункт билета #3
  33. int main()
  34. {
  35.     double* arr = new double[9];
  36.     CreateArray(arr, 9);
  37.     cout << "Array: ";
  38.     for (int i = 0; i < 9; i++)
  39.         cout << arr[i] << " ";
  40.     cout << endl;
  41.     double maxValue;
  42.     int index;
  43.     double sum = GetPositiveSum(arr, index, maxValue);
  44.     cout << "Sum of positive numbers = " << sum << endl;
  45.     cout << "Maximum element index = " << index << endl;
  46.     cout << "Maximum element = " << maxValue << endl;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top