第一道就是说算分数的问题,去掉一个最高分一个最低分,求平均分
#include<stdio.h>
float avescore(float score[],int n)
{
float min=0;
float max=0;
int minindex=0;
int maxindex=0;
float sum=0;
min=score[0];
for(int i=0;i<n;i++)
if(score[i]<min)
{
min=score[i];
minindex=i;
}
score[minindex]=0;
max=score[0];
for(i=0;i<n;i++)
if(score[i]>max)
{
max=score[i];
maxindex=i;
}
score[maxindex]=0;
for(i=0;i<n;i++)
sum+=score[i];
sum=sum/(n-2);
return sum;
}
void main()
{
float score[6]={70,80,90,98,87,86};
float lastscore;
lastscore=avescore(score,6);
printf("the last score is :%5.2f\n",lastscore);
}
运行结果:
the last score is :85.75