#include <iostream> int main() { int n; std::cout << "Enter the number of elements in 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 sum = 0, count = 0; for(int i = 1; i < n; i += 2) { sum += arr[i]; count++; } if(count == 0) { std::cout << "No elements with even indexes in the array"; } else { float average = static_cast<float>(sum) / count; std::cout << "Average of elements with even indexes: " << average; } return 0; }
int main() {
int n;
std::cout << "Enter the number of elements in 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 sum = 0, count = 0;
for(int i = 1; i < n; i += 2) {
sum += arr[i];
count++;
}
if(count == 0) {
std::cout << "No elements with even indexes in the array";
} else {
float average = static_cast<float>(sum) / count;
std::cout << "Average of elements with even indexes: " << average;
}
return 0;
}