C++ Primer Plus 7.12.1

闲着没事写代码。。。呃。。。

#include <iostream>
using namespace std;

double func(double,double);

int main()
{
	cout<<"==<<计算调和平均数>>==\n\n";
	cout<<"请输入两个数:n";
	double a,b;
	while (cin>>a>>b && a != 0 && b != 0)
	{
		cout<<a<<" 和 "<<b<<" 的调和平均数为:"<<func(a,b)<<"\n\n";
		cout<<"请再次输入两个数:\n";
	}
	cout<<"输入错误,再见!\n";
	return 0;
}

double func(double x,double y)
{
	return 2.0 * x * y / (x + y);
}

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

扫码去手机上看