c++ 第六章第二题

来源:互联网 发布:gta5 抗锯齿优化 编辑:程序博客网 时间:2024/06/07 19:36
#include<iostream>#include<cctype>using namespace std;int main(){    double donation[10];    double average = 0, sum = 0;    int i = 0, total = 0;    double temp;    while (cin >> temp && i < 10 && !isdigit(temp)) // 把条件化成语句         {            donation[i] = temp;            sum += donation[i];            i ++;        }        if (i != 0)            average = sum / i;        for (int j = 0; j < i; j ++)            if (donation[j]  > average)                total ++;    cout << "这些数的平均数是:" << average<<endl;    cout << "有"<< total <<"个数大于平均数\n";     return 0;}