计算公式如下:
调和平均数=2.0*x*y/(x+y)
#include <iostream>
double tp(double x, double y);
int main() {
double a, b;
std::cout << "please enter a and b:\n";
std::cin >> a >> b;
while (a != 0 && b != 0) {
std::cout << tp(a, b) << std::endl;
std::cout << "please enter a and b:\n";
std::cin >> a >> b;
}
return 0;
}
double tp(double x, double y) {
double tpz = 2.0 * x * y / (x + y);
return tpz;
}