Skip to content

Instantly share code, notes, and snippets.

@mahata
Created September 13, 2011 20:36
Show Gist options
  • Save mahata/1215077 to your computer and use it in GitHub Desktop.
Save mahata/1215077 to your computer and use it in GitHub Desktop.
C++ Primer 7.1
#include <iostream>
double harmonic_mean(double x, double y);
int main()
{
using namespace std;
double x, y;
cout << "Please input x and y: ";
while (cin >> x >> y) {
cout << "harmonic mean is: " << harmonic_mean(x, y) << endl;
if (0 == int(x) || 0 == int(y)) { break; }
cout << "Please input x and y: ";
}
return 0;
}
double harmonic_mean(double x, double y)
{
return 2.0 * x * y / (x + y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment