2071:【例2.14】平均分
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 19481 通过数: 12655
【题目描述】
已知某班有男同学x位,女同学y位,x位男生平均分是87分,y位女生的平均分是85,问全体同学平均分是多少分?
【输入】
男女同学人数。
【输出】
平均分(保留4位小数)。
【输入样例】
2 3
【输出样例】
85.8000
本题看的就是有没有脑子,不多比比,上代码
(注意是实数)
代码参考:(函数)
#include <bits/stdc++.h>
using namespace std;
double f(double x,double y,double s){
s=(x*87+y*85)/(x+y);
return s;
}
int main()
{
double x, y,s;
cin >> x >> y;
cout<<fixed<<setprecision(4)<<f(x,y,s);
return 0;
}
代码参考:(无函数)
#include <bits/stdc++.h>
using namespace std;
int main()
{
double x, y,s;
cin >> x >> y;
s=(x*87+y*85)/(x+y);
cout<<fixed<<setprecision(4)<<s;
return 0;
}