Написать в C++ программу:
Ввести массив. Найти произведение положительных элементов массива, стоящих после максимального элемента массива.

28 Окт 2019 в 22:41
300 +1
1
Ответы
1
#include <iostream>
int main() {
int n;
std::cout << "Enter the size of the array: ";
std::cin >> n;
int arr[n];
std::cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++) {
std::cin >> arr[i];
}
int maxElement = arr[0];
int maxIndex = 0;
for (int i = 1; i < n; i++) {
if (arr[i] > maxElement) {
maxElement = arr[i];
maxIndex = i;
}
}
int product = 1;
for (int i = maxIndex + 1; i < n; i++) {
if (arr[i] > 0) {
product *= arr[i];
}
}
std::cout << "Product of positive elements after the maximum element: " << product << std::endl;
return 0;
}

Пример работы программы:

Enter the size of the array: 6
Enter the elements of the array: 2 3 5 -4 7 8
Product of positive elements after the maximum element: 56
19 Апр 2024 в 03:37
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир