Given a list of N integers, find its mean (as a double), maximum value, minimum value, and range. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Given a list of N integers, find its mean (as a double), maximum value, minimum value, and range.

Yeah, some help here guys

23rd Mar 2019, 2:10 AM
stanley
4 Answers
+ 3
Please show us your attempt.
23rd Mar 2019, 2:18 AM
Diego
Diego - avatar
+ 3
You first write down the definition. Then from the definition, translate it into code.
23rd Mar 2019, 2:21 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
Kindly show us your attempt first. This way you can learn more about things and improve. If you are stuck or have a doubt, feel free to ask about it here. The problem require you to simply iterate over the array to find the maximum and minimum element respectively. The range is defined by [min,max], where [ and ] signify inclusion. Also, during the iteration, keep adding values of every element to a variable sum to get the average (average=sum/size). These problems can also be solved using standard library functions. Assuming that your data is in an array a[] of size n: 0) For finding the maximum and minimum element of a range/container: auto data = std::minmax_element(a,a+n); The variable data is a pair, where the first element is the minimum value and the second is the maximum value. 1) For finding average of the range of elements: double average = (std::accumulate(a,a+n,0)/static_cast<double>(n)); Accumulate calculates the sum of the elements in the range. This is then used to get the average.
23rd Mar 2019, 3:59 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
0
Show us your attempt
1st Jul 2020, 2:10 PM
Haitham Khalil
Haitham Khalil - avatar