c++ 第六章第二题

#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;
}

猜你喜欢

转载自blog.csdn.net/qq_40860649/article/details/78608595