p281

源程序:

#include <iostream>

using namespace std;

int main()

{

int x, count, sum = 0;

freopen("c:\\input.txt", "r", stdin);

for (count = 0; count<10; count++)

{

cin >> x;

if (cin.eof())

break;

else sum += x;

}

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

system("pause");

return 0;

}

运行结果:

在input.txt中输入10个整数,读10个整数读入文件中,依次相加,直到文件结束停止读入,再求平均值

猜你喜欢

转载自www.cnblogs.com/duanqibo/p/12235728.html