#include<iostream>
using namespace std;
int Count(double a[], int n)
{
int sum = 0;
int count = 0;
// 计算数组所有元素的和
for (int i = 0; i < n; i++)
{
sum += a[i];
}
// 计算平均值
double avg = sum / n;
cout << "平均值为:" << avg << endl;
// 统计大于等于平均值的元素个数
for (int i = 0; i < n; i++)
{
if (a[i] >= avg) {
count++;
cout << a[i] << endl;
}
}
cout << "平均值的元素个数为:" << count;
return count;
}
int main()
{
double a[6] = { 1,2,3,5,7,9};
Count(a, 6);
}
运行结果: