Advertisement
vaziliybober

Untitled

Oct 14th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 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 = new double(n);
  10.   double sum = 0;
  11.  
  12.   for (int i = 0; i < n; i++) {
  13.     cin >> a[i];
  14.  
  15.     if (i % 2 == 0) {
  16.       sum += a[i];
  17.     }
  18.   }
  19.  
  20.   cout << "Исходный массив: ";
  21.   for (int i = 0; i < n; i++) {
  22.     cout << a[i] << " ";
  23.   }
  24.  
  25.   cout << "\n";
  26.  
  27.   for (int i = 0; i < n - 1; i++) {
  28.     for (int j = 0; j < n - i - 1; j++) {
  29.       if (a[j] < a[j + 1]) {
  30.         double temp = a[j];
  31.         a[j] = a[j + 1];
  32.         a[j + 1] = temp;
  33.       }
  34.     }
  35.   }
  36.  
  37.   cout << "Отсортированный по убыванию масив: ";
  38.   for (int i = 0; i < n; i++) {
  39.     cout << a[i] << " ";
  40.   }
  41.  
  42.   cout << "\n";
  43.  
  44.   cout << "Сумма элементов с четными номерами: ";
  45.   cout << sum;
  46.  
  47.  
  48.   return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement