Description
Write a program that reads n numbers, computes their average, and finds out how many numbers are above the average.
Input
The first line is a positive integer t for the number of test cases.
Each test case contains two lines. The first line is an integer n (0<n<=100). The second line contains n numbers.
Output
For each test case, output how many numbers above the average in one line.
Sample Input
2
3
2 1.5 2.5
4
2 -6 2 6
Sample Output
1
3
// Date:2020/4/9
// Author:xiezhg5
#include <stdio.h>
int main(void)
{
double a[100]={0},sum=0,average=0;
int m,n,i,cnt=0;
scanf("%d\n",&m); //注意一定要加回车符标测要求
while(m--)
{
scanf("%d",&n); //读入n表示接下来要输n个数
//这里一定要重新初始化(因为要读入不同的数)
sum=0;
average=0;
cnt=0;
for(i=0;i<=n-1;i++)
{
//for循环为数组元素下标赋值
scanf("%lf",&a[i]);
sum=sum+a[i]; //累加
}
//求平均
average=sum/(1.0*n);
//再来一层for循环进行比较
for(i=0;i<=n-1;i++)
{
if(a[i]>average)
cnt++; //计数变量
}
printf("%d\n",cnt);
}
return 0;
}