#include <stdio.h>
#include <stdlib.h>
/*
写1个程序,接收输入班级的人数, 然后依次的输入每1个学员的成绩.
将学员的成绩存储在数组之中.
输入完毕之后, 显示总成绩和平均成绩.
然后再去掉1个最高分和1个最低分, 再计算平均成绩.*/
void show1( double score[],int n );
int main()
{
printf("请输入班级的人数:\n");
int num = 0;
scanf("%d",&num);
double a[1000];
show1(a,num);
system("pause");
return 0;
}
void show1( double score[],int n ){
int i = 0;
double sum = 0,avg = 0;
for(i = 0;i<n;i++){
printf("请输入第%d个学员的分数:\n",i+1);
scanf("%lf",&score[i]);
sum = sum + score[i];
}
avg = sum/n;
printf("总成绩是%.1lf,平均成绩是%.1lf\n",sum,avg);
int j = 0;
double max = 0,min = 0;
max = min = score[0];
for(j=0;j<n;j++){
if(max<score[j]){
max = score[j];
}
if(min>score[j]){
min = score[j];
}
}
double sum1 = sum - max- min;
double avg1 = sum1/(n-2);
printf("去掉1个最高分和1个最低分后的平均成绩是%.1lf\n",avg1);
} |
|