编写一个函数,输出一维数组中所有低于平均值的元素值。用c++写,谢谢!!voidLessAverage(doublea[],intn
void LessAverage(double a[], int number) //把数组长度number也传进来,后面简单点。
{
double average = 0.0, sum = 0.0;
for(int i = 0; i <= number; i++)
{
sum = sum + a[i];
}
average = sum / number;
for(int i = 0; i <= number; i++)
{
if(a[i] < average)
cout<<a[i]<<endl;
}
}