Solutions

This commit is contained in:
Markus Schmidt 2025-10-21 19:36:38 +02:00
commit d3aa42a3e0
64 changed files with 2726 additions and 0 deletions

36
sheet1/A/means.cpp Normal file
View file

@ -0,0 +1,36 @@
#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;
}