当前位置:网站首页>7-4 harmonic average

7-4 harmonic average

2022-07-06 16:43:00 HBUcs2020

Record a very stupid mistake

n-- after n Finally changed to 0, I still use n To divide

#include<iostream>
using namespace std;
int main()
{
    int n;
        cin>>n;
    double sum=0;
int a=n;
    while(n--)
    {
        double x;
        cin>>x;
        //printf(" %lf  %lf\n",1/x,sum);
        sum+=1/x;
    }
    //sum=sum/n;
    //printf("%lf\n",sum/n);
    printf("%.2f",1.0/(sum/a));
    return 0;
}

原网站

版权声明
本文为[HBUcs2020]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131314584193.html