0

help me

I need to determine the average age of C++ code that's the task --------------------------------------- Average age This code declares an array called ages, which stores the ages of all employees in the company. The code also includes a for loop that outputs an array. Task Modify the code to calculate and display the average age of employees. You don't need to output the array. here is the code -------------------------------------- #include <iostream> using namespace std; int main() { int ages[] = {19, 24, 36, 45, 56, 52, 21, 27, 24, 34, 29, 60, 40, 42, 45, 47, 22, 30, 34, 20, 18, 26, 51, 43, 47, 39, 22, 34, 56, 52, 21, 27, 24, 37, 19, 24, 36, 45, 44, 49, 23, 25, 19, 40, 29, 60, 40, 42, 45, 47, 61, 30, 19, 43, 47, 39, 41, 46, 29, 24, 21, 25, 28}; int size = 63; int *p = ages; for(int i=0;i<size;i++) { cout << *p << endl; p++; } }

2nd May 2024, 9:48 AM
WLAIN CORNIT
WLAIN CORNIT - avatar
2 Respuestas
+ 8
Sum of all the given age and then devide by no of ages
2nd May 2024, 10:08 AM
A͢J
A͢J - avatar
0
in c++11 int result = std::accumulate(array.begin(), array.end(), 0) / array.size() in c++23 result | std::ranges::transform(0, std::ostream_iterator<int>{ result / array.size() }); I assume you are using the standard array
2nd May 2024, 5:56 PM
RuntimeTerror
RuntimeTerror - avatar