去掉一个最高分和一个最高分然后取其余3名评委的平均分作为最后得分用c语言
时间: 2023-03-28 16:01:34 浏览: 140
可以使用以下代码实现:
#include <stdio.h>
int main() {
int scores[5]; // 存储5个评委的分数
int sum = ; // 存储总分
int max1 = , max2 = ; // 存储最高分和次高分
// 输入5个评委的分数
for (int i = ; i < 5; i++) {
printf("请输入第%d个评委的分数:", i+1);
scanf("%d", &scores[i]);
// 更新最高分和次高分
if (scores[i] > max1) {
max2 = max1;
max1 = scores[i];
} else if (scores[i] > max2) {
max2 = scores[i];
}
// 累加总分
sum += scores[i];
}
// 计算最终得分
int final_score = (sum - max1 - max2) / 3;
printf("最终得分为:%d\n", final_score);
return ;
}
相关问题
用c语言写一个五个评委为参赛选手打分,选手最后得分要去掉一个最高分,去掉一个最低分,然后求平均分作为选手成绩。不用数组
您好!感谢您使用 ChitGPT 进行对话。根据您的需求,我可以提供以下 C 语言代码,实现对五个评委为参赛选手打分,选手最后得分要去掉一个最高分,去掉一个最低分,然后求平均分作为选手成绩的功能,但不使用数组:
```c
#include <stdio.h>
#include <limits.h>
int main() {
int judge1, judge2, judge3, judge4, judge5;
int highest, lowest, sum, avg;
sum = 0;
highest = INT_MIN; /* initialize as smallest value */
lowest = INT_MAX; /* initialize as largest value */
/* read in scores from the judges */
printf("Enter score from judge 1: ");
scanf("%d", &judge1);
printf("Enter score from judge 2: ");
scanf("%d", &judge2);
printf("Enter score from judge 3: ");
scanf("%d", &judge3);
printf("Enter score from judge 4: ");
scanf("%d", &judge4);
printf("Enter score from judge 5: ");
scanf("%d", &judge5);
/* find the highest and lowest scores */
if (judge1 > highest) {
highest = judge1;
}
if (judge1 < lowest) {
lowest = judge1;
}
if (judge2 > highest) {
highest = judge2;
}
if (judge2 < lowest) {
lowest = judge2;
}
if (judge3 > highest) {
highest = judge3;
}
if (judge3 < lowest) {
lowest = judge3;
}
if (judge4 > highest) {
highest = judge4;
}
if (judge4 < lowest) {
lowest = judge4;
}
if (judge5 > highest) {
highest = judge5;
}
if (judge5 < lowest) {
lowest = judge5;
}
/* calculate the sum of the scores */
sum = judge1 + judge2 + judge3 + judge4 + judge5 - highest - lowest;
/* calculate the average score */
avg = sum / 3;
/* print out the final score */
printf("Final score: %d\n", avg);
return 0;
}
```
希望这个代码能够满足您的需求。如果还有其他需要,请随时问我。
用C语言输入n个评委的打分,计算并输出参赛选手的最后得分。计算方法为去除一个最高分和去除一个最低分,其余的进行平均,得出参赛选手的最后得分
下面是C语言的代码实现:
```c
#include <stdio.h>
#define MAX_JUDGE_NUM 10 // 最多的评委人数
int main() {
int n; // 评委人数
int scores[MAX_JUDGE_NUM]; // 评委们的打分
int max_score = -1, min_score = 101; // 最高分和最低分
int sum_score = 0; // 所有评委的总分数
printf("请输入评委的人数(不超过%d个):", MAX_JUDGE_NUM);
scanf("%d", &n);
// 读入每个评委的打分
for (int i = 0; i < n; i++) {
printf("请输入第%d个评委的打分:", i + 1);
scanf("%d", &scores[i]);
// 更新最高分和最低分
if (scores[i] > max_score) {
max_score = scores[i];
}
if (scores[i] < min_score) {
min_score = scores[i];
}
sum_score += scores[i]; // 累加总分数
}
// 去掉一个最高分和一个最低分
sum_score -= max_score;
sum_score -= min_score;
// 计算最终得分并输出
double final_score = sum_score * 1.0 / (n - 2);
printf("参赛选手的最终得分为:%.2f\n", final_score);
return 0;
}
```
程序的核心思路是读入每个评委的打分,同时记录下最高分和最低分,累加总分数。然后去掉一个最高分和一个最低分,计算最终得分并输出。需要注意的是,最终得分要用 `double` 类型存储,否则可能会丢失精度。