代码如下
//5个成绩,去掉最高分,去掉最低分,求 平均分#include <stdio.h>int main(){int min,max,average,sum,i;int score[5];printf("请输入成绩:");for(i=0;i<5;i++){scanf("%d",&score[i]);}printf("\n"); min=score[0]; max=score[0]; sum=0;for(i=0;i<5;i++){if(score[i]>max){max=score[i];}if(score[i]<min){min=score[i];}sum+=score[i];}printf("总分为:%d\n\n",sum);printf("最高分为:%d\n\n",max);printf("最低分为:%d\n\n",min);average=sum/5;printf("此时,平均分为:%d\n\n",average);average=(sum-min-max)/3;printf("去掉最高分和最低分后,平均成绩为:%d\n",average);}
测试输出
支持浮点数
将成绩改为浮点数格式的:
//5个成绩,去掉最高分,去掉最低分,求 平均分#include <stdio.h>int main(){float min,max,average,sum;int i;float score[5];printf("请输入成绩:");for(i=0;i<5;i++){scanf("%f",&score[i]);}printf("\n"); min=score[0]; max=score[0]; sum=0;for(i=0;i<5;i++){if(score[i]>max){max=score[i];}if(score[i]<min){min=score[i];}sum+=score[i];}printf("总分为:%f\n\n",sum);printf("最高分为:%f\n\n",max);printf("最低分为:%f\n\n",min);average=sum/5;printf("此时,平均分为:%f\n\n",average);average=(sum-min-max)/3;printf("去掉最高分和最低分后,平均成绩为:%f\n",average);}
测试输出:
如果觉得《【C语言】5个成绩 去掉最高分 去掉最低分 求 平均分》对你有帮助,请点赞、收藏,并留下你的观点哦!