Since you tagged this with C++, I would use std::vector
objects mixed with the std::sort()
algorithm for making it easy to find these stats. Here’s a simple example.
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<float> numbers = { 1, 4, 3, 2 };
std::sort(numbers.begin(), numbers.end());
// numbers = { 1, 2, 3, 4 }
float min = numbers.front();
float max = numbers.back();
float median;
if (numbers.size() % 2) { // odd number of elements
median = numbers[numbers.size() / 2];
}
else { // even number of elements
median = (numbers[numbers.size() / 2] + numbers[numbers.size() / 2 - 1]) / 2;
}
}
2
solved Get the largest, average and smallest value [closed]