Advertisement
vaziliybober

Untitled

Oct 14th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7.     const int n = 5;
  8.  
  9.     double a[n];
  10.     double sum = 0;
  11.  
  12.     cout << "Enter the array: ";
  13.     for (int i = 0; i < n; i++) {
  14.         cin >> a[i];
  15.  
  16.         if ((i + 1) % 2 == 0) {
  17.             sum += a[i];
  18.         }
  19.     }
  20.  
  21.     cout << endl << "Original array: ";
  22.     for (int i = 0; i < n; i++) {
  23.         cout << a[i] << " ";
  24.     }
  25.  
  26.     cout << "\n";
  27.  
  28.     for (int i = 0; i < n - 1; i++) {
  29.         for (int j = 0; j < n - i - 1; j++) {
  30.             if (a[j] < a[j + 1]) {
  31.                 double temp = a[j];
  32.                 a[j] = a[j + 1];
  33.                 a[j + 1] = temp;
  34.             }
  35.         }
  36.     }
  37.  
  38.     cout << "Sorted array: ";
  39.     for (int i = 0; i < n; i++) {
  40.         cout << a[i] << " ";
  41.     }
  42.  
  43.     cout << endl << "Sum of elements: " << sum << endl;
  44.  
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement