评委评分程序。输入评委人数,依次输入对选手的评分,评分是百分制,去掉一个最高分,最低分,再算出平均分作为选手的得分,输出选手得分,保留3位小数。
程序源码:
#include <stdio.h>
int main() {
int numJudges;
printf("请输入评委人数: ");
scanf("%d", &numJudges);
if (numJudges <= 2) {
printf("评委人数必须大于等于3。\n");
return 1;
}
int i;
double totalScore = 0.0;
double minScore = 100.0; // 初始化为一个大数
double maxScore = 0.0; // 初始化为一个小数
for (i = 0; i < numJudges; i++) {
double score;
printf("请输入第%d位评委的评分: ", i + 1);
scanf("%lf", &score);
// 更新总分
totalScore += score;
// 更新最低分
if (score < minScore) {
minScore = score;
}
// 更新最高分
if (score > maxScore) {
maxScore = score;
}
}
// 计算得分,去掉一个最高分和一个最低分
totalScore = totalScore - minScore - maxScore;
double averageScore = totalScore / (numJudges - 2);
// 输出选手得分,保留3位小数
printf("选手得分为: %.3lf\n", averageScore);
return 0;
}