问题:
解答:
#include <iostream>
#include <array>
using namespace std;
#define MAX 10
int main()
{
array<float, MAX> arr;
float sum=0;
float average=0;
int i = 0;
int count=0;
int bigger = 0;
for (i = 0; i < MAX; i++)
{
cout << "请输入donation的值:" << endl;
cin >> arr[i];
if (cin.fail())
{
cout << "输入的非数字,结束输入!" << endl;
break;
}
sum += arr[i];
count++;
}
average = sum / count;
for (int i = 0; i < count; i++)
{
if (arr[i] > average)
{
bigger++;
}
}
cout << "这些数字的平均值为:" << average << endl;
cout << "大于平均值的有" << bigger << "个" << endl;
return 0;
}
运行结果:
考查点:
- if
- 计算
2024年8月27日20:05:05