求若干整數的平均數,結果保留三位小數。
輸入樣例:第一個數字代表數據個數
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提交時,注釋此句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提交時,注釋此句return 0;
}