Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- const int n = 5;
- double* a = new double(n);
- double sum = 0;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- if (i % 2 == 0) {
- sum += a[i];
- }
- }
- cout << "Исходный массив: ";
- for (int i = 0; i < n; i++) {
- cout << a[i] << " ";
- }
- cout << "\n";
- for (int i = 0; i < n - 1; i++) {
- for (int j = 0; j < n - i - 1; j++) {
- if (a[j] < a[j + 1]) {
- double temp = a[j];
- a[j] = a[j + 1];
- a[j + 1] = temp;
- }
- }
- }
- cout << "Отсортированный по убыванию масив: ";
- for (int i = 0; i < n; i++) {
- cout << a[i] << " ";
- }
- cout << "\n";
- cout << "Сумма элементов с четными номерами: ";
- cout << sum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement