36 lines
No EOL
760 B
C++
36 lines
No EOL
760 B
C++
#include <iostream>
|
|
#include <cmath>
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
|
|
void means(int a, int b, int c, double &ar, double &ge, double &ha) {
|
|
ar = (a+b+c) / 3.0;
|
|
|
|
|
|
ge = pow(a,1.0/3.0) * pow(b,1.0/3.0) * pow(c,1.0/3.0); //do it instead of pow(a*b*c,1.0/3.0) to prevent integer overflow
|
|
|
|
ha = 3.0 / (1.0/a +1.0/b +1.0/c);
|
|
}
|
|
|
|
void means_vector(const vector<int> &input, double &ar, double &ge, double &ha) {
|
|
int size = input.size();
|
|
|
|
if (size == 0) {
|
|
cout << "Empty input" << endl;
|
|
return;
|
|
}
|
|
|
|
ar = 0;
|
|
ge = 1;
|
|
ha = 0;
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
ar += input.at(i);
|
|
ge *= pow(input.at(i), 1.0 / size);
|
|
ha += 1.0 / input.at(i);
|
|
}
|
|
|
|
ar /= size;
|
|
ha = size / ha;
|
|
} |