请教高手帮我做一个C语言编程题

2024-11-28 14:05:01
推荐回答(4个)
回答1:

自己帮你弄了下,你看看:
#include
#include

#define NUM 10

void test(float const score[NUM])
{
int i;
for(i=0;i {
if(score[i]<1||score[i]>100)
printf("the score of number %d is error!\n",i);
}
}
int main(void)
{
float score[NUM]={80,82,90,93,85,86,90,92,89,87};
float maxScore=1,minScore=100,sum=0;
float maxDscore=0,minDscore=100;
int i,max,min;
int maxD,minD;

clrscr(); /*清屏*/
test(score); /*校对是否都在1-100间*/

/*找出最大最小数下标与数值*/
for(i=0;i {
if(maxScore {
maxScore = score[i];
max = i;
}
if(minScore>score[i])
{
minScore = score[i];
min = i;
}
}

/*求其余几个的总分*/
for(i=0;i {
if(i!=min&&i!=max)
sum+=score[i];
}

/*求平均分*/
if(max==min) sum/=9;
else sum/=8;

/*找出偏差最大最小*/
for(i=0;i {
if(i==min||i==max) continue;
if(maxDscore {
maxDscore = fabs(score[i]-sum);
maxD = i;
}
if(minDscore>fabs(score[i]-sum))
{
minDscore = fabs(score[i]-sum);
minD = i;
}
}

printf("all scores:\n");
for(i=0;i {
printf("%.3f ",score[i]);
if(!((i+1)%10)) printf("\n");
}
printf("minimum score:%.3f\n",score[min]);
printf("maximum score:%.3f\n",score[max]);
printf("average score:%.3f\n",sum);
printf("the most impartial one is:%d, score:%.3f ,diff:%.3f\n",minD,score[minD],minDscore);
printf("the most unfair one is:%d, score:%.3f ,diff:%.3f\n",maxD,score[maxD],maxDscore);
getch();
return 0;
}

回答2:

刚试了下,有点难度,难度主要是在去掉最高分和最低分上
其实,你自己慢慢想就会明白,很简单

回答3:

二楼太有耐心了,分一定要给他~~~

回答4:

这么简单的问题,浪费时间