#include <iostream>
#include <vector>
using namespace std;
double geometric_mean(std::vector<float> const& data)
{
auto product = 1.0;
for (auto x : data) product *= x;
return std::pow(product, 1.0 / data.size());
}
int main()
const unsigned int M = 3;
const unsigned int N = 5;
std::vector<float> g;
float TV[6][7]= {
{ 7.2, 3.6, 4.8, 6.3, 0, 3.2, 0 },
{ 4.5, 2.3, -5.1, 1.3, 8.1, 0, 2.4 },
{ 6.3, -2.4, 8.4, 0, 1.6, 1.5, 0 },
{ 1.7, 6.8, 1.3, 9.5, 0, 0, 1.8 },
{ 2.3, 2.6, 8.5, 0.8, 2.6, 0, 0 },
{ 9.5, 1.6, -3.8, 2.6, -1.3, 3.3, -0.8 }
};
for (int i = 0; i < N; i++)
float max = TV[0][i];
for (int j = 0; j < M; j++)
if (TV[j][i] >= max) max = TV[j][i];
cout << "max M[" << i+1 << "]=" << max<<endl;
g.push_back(max);
cout << "GM=" << geometric_mean(g)<<endl;
system("pause");
Объяснение:
#include <iostream>
#include <vector>
using namespace std;
double geometric_mean(std::vector<float> const& data)
{
auto product = 1.0;
for (auto x : data) product *= x;
return std::pow(product, 1.0 / data.size());
}
int main()
{
const unsigned int M = 3;
const unsigned int N = 5;
std::vector<float> g;
float TV[6][7]= {
{ 7.2, 3.6, 4.8, 6.3, 0, 3.2, 0 },
{ 4.5, 2.3, -5.1, 1.3, 8.1, 0, 2.4 },
{ 6.3, -2.4, 8.4, 0, 1.6, 1.5, 0 },
{ 1.7, 6.8, 1.3, 9.5, 0, 0, 1.8 },
{ 2.3, 2.6, 8.5, 0.8, 2.6, 0, 0 },
{ 9.5, 1.6, -3.8, 2.6, -1.3, 3.3, -0.8 }
};
for (int i = 0; i < N; i++)
{
float max = TV[0][i];
for (int j = 0; j < M; j++)
{
if (TV[j][i] >= max) max = TV[j][i];
}
cout << "max M[" << i+1 << "]=" << max<<endl;
g.push_back(max);
}
cout << "GM=" << geometric_mean(g)<<endl;
system("pause");
}
Объяснение: