求若干整數(shù)的平均數(shù),結(jié)果保留三位小數(shù)。
輸入樣例:第一個(gè)數(shù)字代表數(shù)據(jù)個(gè)數(shù)
3 6 5 18
4 1 2 3 4
輸出樣例:
9.667
2.500
#include<iostream>#include<fstream>using namespace std;int main(){ ifstream cin("test.txt");//向OJ提交時(shí),注釋此句 cout.PRecision(3); cout << fixed; int n; while (cin >> n) { double sum = 0; for (int i = 0; i < n; ++i) { double tmp; cin >> tmp; sum += tmp; } cout << sum*1.0 / n << endl; } system("pause");//向OJ提交時(shí),注釋此句 return 0;}
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注