正文

4.歌星大奖赛2005-09-10 15:12:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/xiangyu/1658.html

分享到:

4.歌星大奖赛 在歌星大奖赛中,有10个评委为参赛的选手打分,分数为1~100分。选手最后得分为:去掉一个最高分和一个最低分后其余8个分数的平均值。请编写一个程序实现。 *问题分析与算法实现 这个问题的算法十分简单,但是要注意在程序中判断最大、最小值的变量是如何赋值的。 *程序说明与注释 #include<stdio.h> void main() { int integer,i,max,min,sum; max=-32768; /*先假设当前的最大值max为C语言整型数的最小值*/ min=32767; /*先假设当前的最小值min为C语言整型数的最大值*/ sum=0; /*将求累加和变量的初值置为0*/ for(i=1;i<=10;i++) { printf("Input number %d=",i); scanf("%d",&integer); /*输入评委的评分*/ sum+=integer; /*计算总分*/ if(integer>max)max=integer; /*通过比较筛选出其中的最高分*/ if(integer<min)min=integer; /*通过比较筛选出其中的最低分*/ } printf("Canceled max score:%d\nCanceled min score:%d\n",max,min); printf("Average score:%d\n",(sum-max-min)/8); /*输出结果*/ } *运行结果 Input number1=90 Input number2=91 Input number3=93 Input number4=94 Input number5=90 Input number6=99 Input number7=97 Input number8=92 Input number9=91 Input number10=95 Canceled max score:99 Canceled min score:90 Average score:92 *思考题 题目条件不变,但考虑同时对评委评分进行裁判,即在10个评委中找出最公平(即评分最接返平均分)和最不公平(即与平均分的差距最大)的评委,程序应该怎样实现?

阅读(33522) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册