#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
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: 6Enter the elements of the array: 2 3 5 -4 7 8
Product of positive elements after the maximum element: 56