#include <iostream>
double harmonic(float a,float b);
int main() {
using namespace std;
float a,b;
cout<<"Please input two numbers:";
while(cin>>a>>b&&a&&b)
{
cout<<"The harmonic mean of the numbers is: "
<<harmonic(a,b)<<endl;
cout<<"Next two numbers:";
}
return 0;
}
double harmonic(float a,float b)
{
return (2.0*a*b)/(a+b);
}
C++primer plus 6th 第7章7.1编程答案
最新推荐文章于 2025-11-24 10:48:04 发布
本文介绍了一个使用C++实现的简单程序,用于计算两个浮点数的谐波平均数。程序首先提示用户输入两个数字,然后计算并输出这两个数字的谐波平均数。此过程在一个循环中重复进行,直到用户输入无效数据为止。
1万+

被折叠的 条评论
为什么被折叠?



