30 lines
No EOL
597 B
C++
30 lines
No EOL
597 B
C++
#include "../ex1A_mean_values/means.h"
|
|
#include <cmath>
|
|
#include <vector>
|
|
|
|
void calculate_means(int a, int b, int c, double &am, double &gm, double &hm)
|
|
{
|
|
am = (a + b + c)/3.0;
|
|
gm = exp((log(a)+log(b)+log(c))/3);
|
|
hm = 3.0/(1.0/a + 1.0/b + 1.0/c);
|
|
}
|
|
|
|
void calculate_means(std::vector<int> numbers, double &am, double &gm, double &hm)
|
|
{
|
|
int n = numbers.size();
|
|
|
|
am = 0.;
|
|
gm = 0.;
|
|
hm = 0.;
|
|
|
|
for (int i = 0; i < n; ++i)
|
|
{
|
|
am += numbers[i];
|
|
gm += log(numbers[i]);
|
|
hm += 1.0/numbers[i];
|
|
}
|
|
|
|
am /= n;
|
|
gm = exp(gm/n);
|
|
hm = n/hm;
|
|
} |