题解 | #公务员面试#
公务员面试
https://www.nowcoder.com/practice/f3a134908d5b41869f14f58307008a97
#include <stdio.h> int main() { int score[10] = { 0 }; int i = 0; int max = 0; int min = 0; int sum = 0; double aver = 0; while(scanf("%d",score) != EOF) { //i从1开始,是因为在循环条件中已经读取过一次数据 for(i = 1; i < 7; i++) { scanf("%d", score + i); } max = score[0]; min = score[0]; for(i = 1; i < 7; i++) { //找出最高分 if(score[i] > max) { max = score[i]; } //找出最低分 if(score[i] < min) { min = score[i]; } } for(i = 0; i < 7; i++) { //求除最高分和最低分外的成绩和 if(score[i] != max && score[i] != min) { sum += score[i]; } } printf("%.2f\n",sum/5.0); sum = 0;//执行完一组计算后sum需要清零 } return 0; }