一直输入两个数,直到其中一个为0,对两个数都求它们的调和平均数。调和平均数=2xy/(x+y)。
#include<iostream>
using namespace std;
int main()
{
int i=0,n=0;
float a,b,s[10];
cin>>a>>b;
//判断输入的两个数是否有0
while(a!=0 && b!=0)
{
s[i]=2*a*b/(a+b);
i++;
n+=1;
cin>>a>>b;
}
if(n!=0)
{ for(int j=0;j<n;j++)
cout<<s[j]<<"\t";
cout<<endl;
}
else
cout<<"第一组数据有0"<<endl;
system("pause");
return 0;
}