平均分输出
怎么让平均分输出为78.6
#include <stdio.h>
#include <stdlib.h>
#define N 10
int cmp(const void *a,const void *b){
return *(int*)b - *(int*)a;
}
int Sum(int score[]){
int s = 0,i;
for(i = 0 ; i < N ; i++)
s += score[i];
return s;
}
int Max(int score[]){
return score[0];
}
int Min(int score[]){
return score[N-1];
}
double Avg(int s){
return (s + 0.0) / N;
}
int main()
{
int score[N]={67,98,75,63,82,79,81,91,66,84};
int i,sum;
sum = Sum(score);
qsort(score,N,sizeof(int),cmp);//sort it
printf("Total score : %d\n",sum);
printf("Max score : %d\n",Max(score));
printf("Min Score : %d\n",Min(score));
printf("Average score : %f\n",Avg(sum));
printf("\n成绩排序:\n");
for(i = 0 ; i < N ; i++)
{
printf("Rank %d's score : %d\n",i+1,score[i]);
}
return 0;
}
平均分只能输成
Average score : 78.600000
我的结果是:
Total score : 786 Max score : 98 Min Score : 63 Average score : 78.600000 成绩排序: Rank 1's score : 98 Rank 2's score : 91 Rank 3's score : 84 Rank 4's score : 82 Rank 5's score : 81 Rank 6's score : 79 Rank 7's score : 75 Rank 8's score : 67 Rank 9's score : 66 Rank 10's score : 63
举报