平均身高
平均身高
http://www.nowcoder.com/questionTerminal/b0e489a749f448e2b37f26ef56a76e58
分析:
读入五个浮点数求和平均即可。
题解:
#include <bits/stdc++.h>
using namespace std;
int main() {
float a, b, c, d, e;
//分别用float读入五门不同的成绩
scanf("%f %f %f %f %f", &a, &b, &c, &d, &e);
//对所有成绩进行累加然后求均值输出。
float avg = (a+b+c+d+e) / 5.f;
printf("%.2f\n", avg);
return 0;
}题解2:
#include <bits/stdc++.h>
using namespace std;
int main() {
float a[5];
float sum = 0.f;
//申请数组,然后将成绩读入到数组中,并顺带求成绩总和。
for(int i = 0; i < 5; ++i) {
scanf("%f", &a[i]);
sum += a[i];
}
//输出平均成绩
printf("%.2f\n", sum / 5.f);
return 0;
}总结:
简单求和计算平均数。
查看9道真题和解析