当前位置:网站首页>L1-068 harmonic average (10 points)

L1-068 harmonic average (10 points)

2022-06-12 04:27:00 Liabilities between persons^

L1-068 Harmonic mean (10 branch )

N The arithmetic average of positive numbers is the sum of these numbers divided by N, Their harmonic mean is the reciprocal of their reciprocal arithmetic mean . Please calculate the harmonic average of a given series of positive numbers .

Input format :
Each input contains 1 Test cases . Each test case is No 1 Line gives a positive integer N (≤1000); The first 2 Line is given N It's a positive number , It's all in the range [0.1,100] Inside .

Output format :
Output the harmonic average of a given sequence in one row , Output after decimal point 2 position .

sample input :

8
10 15 12.7 0.3 4 13 1 15.6

sample output :

1.61
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<sstream>

using namespace std;
typedef long long ll;
const int N=10010;

int main()
{
    
	int n;
	cin >> n;
	double sum = 0;
	for(int i = 0; i < n; i ++ )
	{
    
		double x;
		cin >> x;
		sum += 1.0 / x;
	}
	cout << sum << endl;
	printf("%.2lf",1.0 / (sum / n));
	return 0;
}



原网站

版权声明
本文为[Liabilities between persons^]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010950285803.html

随机推荐