Created
September 13, 2011 20:36
-
-
Save mahata/1215077 to your computer and use it in GitHub Desktop.
C++ Primer 7.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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