#include <iostream>
#include <numeric>
int main() {
int ages[5] = {21, 19, 35, 42, 28};
std::cout << "Initial Array Values" << std::endl;
std::cout << "The first person's age is: " << ages[0] << std::endl;
std::cout << "The last person's age is: " << ages[4] << std::endl;
ages[1] = 20;
std::cout << "\nArray after modification" << std::endl;
std::cout << "The second person's age is updated to: " << ages[1] << std::endl;
int sum_of_ages = 0;
std::cout << "\nIterating through all ages" << std::endl;
for (int age : ages) {
std::cout << "Age: " << age << std::endl;
sum_of_ages += age;
}
std::cout << "The total sum of all ages is: " << sum_of_ages << std::endl;
std::cout << "The average age is: " << static_cast<double>(sum_of_ages) / 5 << std::endl;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: