自考新教材-p279_2

源程序:

#include <iostream>

using namespace std;

int main()

{

int x, count, sum = 0;

freopen("c:\input.txt", "r", stdin); //将标准输入重定向到文件input.txt

for (count = 0; count<10; count++)   //从输入流中读入10个整数进行处理

{

cin >> x;

sum += x;

}

cout << "前10个整数的平均值=" << 1.0*sum / 10 << endl;

system("pause");

return 0;

}

运行结果:

在input.txt文件中输入10个整数,将标准输入重定向到该文件,读此10个数,相加,再求平均值

原文地址:https://www.cnblogs.com/duanqibo/p/12235710.html