#include "stdio.h"
void main()
{
int i,total_score=0,each_score;
int max=0,min=0;
for(i=1;i<=4;i++)
{
printf("请输入成绩:");
scanf("%d",&each_score);
while(min>each_score)//min初始为0,只有负数才比0小,得分会是负数吗?
min=each_score;
while(max<each_score)
max=each_score;
total_score=total_score+each_score;
}
total_score=total_score-max-min;
printf("去掉最高分和最低分后总分是:%d",total_score);
}
--------------------给你一种我的思路--------------------
有几个得分,就准备几个变量;
一次性读取所有变量;在准备max,min;
寻找读取分的的最大值和最小值;
最后,你懂的;
--------------------------------------------------------
给楼主实现下:
#include "stdio.h"
void main()
{
int max,min,total = 0;
int fenshu[4];//假设有4个给分人.可以用变量设置,给分人的个数;
for(int i=0;i<=3;i++)
{
printf("输入分数:");
scanf("%d",&fenshu[i]);
}
for(i=0;i<=3;i++) total += fenshu[i];
max = min = fenshu[0];
for(i=0;i<=3;i++)
{
if(max<fenshu[i])
max = fenshu[i];
if(min>fenshu[i])
min = fenshu[i];
}
printf("最高分是%d\n",max);
printf("最低分数是%d\n",min);
printf("去掉最高和最低分后,得分为%d\n",(total-max-min));
}
[
本帖最后由 suntea 于 2010-7-3 17:31 编辑 ]