95分求助!!!

B2054 求平均年龄

_dhrxx_ @ 2021-12-24 19:07:16

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    float a[10000],s;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        s=s+a[i];
    }
    s=s/n;
    printf("%0.2f",s);
    return 0;
} 

哪错了,过样例了呀


by Water_Cows @ 2021-12-24 19:09:31

float 开成 double


by HarunluoON @ 2021-12-24 19:10:28

s没有初始值


by OldVagrant @ 2021-12-24 19:12:00

@叶洛洛 float开成int,然后s开成double并赋初值为0
名字好评


by bsTiat @ 2021-12-24 19:15:04

嘿嘿,洛洛,嘿嘿,我的洛洛(


by _dhrxx_ @ 2021-12-24 19:52:03

谢谢


by Streetlights @ 2022-02-14 15:36:25

想问一下为什么不能用float?


by 神啊波吃的 @ 2022-05-01 11:30:42

@Streetlights float的精度太小,double才是小数类型


by break1 @ 2022-09-13 22:00:07

精度问题


by FengYuXinMing @ 2022-09-15 19:35:15

double是双精度


by FengYuXinMing @ 2022-09-15 19:38:57

float只支持9位小数(可能说错)


|