算出全部的平均,再看有幾個人在平均以上,最後算出百分比。
#include <stdio.h>
#include <stdlib.h>
int main(void){
int amount,people,i;
int score[1001],counter;
double average,percent;
scanf("%d",&amount);
while(amount--){
scanf("%d",&people);
average=0;
for(i=0;i<people;i++){
scanf("%d",&score[i]);
average+=score[i];
}
average/=people;
counter=0;
for(i=0;i<people;i++){
if(score[i] > average) ++counter;
}
percent=((double)counter/people)*100;
printf("%.3lf%%\n",percent);
}
return 0;
}
沒有留言:
張貼留言