功能:输入十个分数,去掉最高分和最低分,并求剩下八个数的平均数。
#include <stdio.h>
#define NUM 10
int main ()
{
int i;
float score[NUM];
float sum=0,ave;
float max,min;
printf ("input the score of players:");
for (i=0;i<NUM;i++)
{
scanf ("%f",&score[i]);
sum+=score[i];
}
max=min=score[0]; //将最大最小值均赋予第一个数
for (i=0;i<NUM;i++)
{
if (score[i]>max)
{
max=score[i]; //求出最大值
}
if (score[i]<min) //求出最小值
{
min=score[i];
}
}
ave=(sum-max-min)/(NUM-2);
printf("The highest score is:%-4.1f\n",max); // 左对齐保留四个字符,精度为一位小数
printf("The lowest score is:%-4.1f\n",min);
printf("The sum is:%-4.1f\n",sum);
printf("The ave is:%-4.1f\n",ave);
return 0;
}