用c语言写一个五个评委为参赛选手打分,选手最后得分要去掉一个最高分,去掉一个最低分,然后求平均分作为选手成绩。不用数组
时间: 2024-05-05 16:19:30 浏览: 105
基于C语言实现比赛评分系统【100010801】
您好!感谢您使用 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;
}
```
希望这个代码能够满足您的需求。如果还有其他需要,请随时问我。
阅读全文