QWQ 啊!95分 ,哪里错了呀?各位大神求助QWQ?

B2054 求平均年龄

qse_5858 @ 2024-09-01 22:31:48

B2054 求平均年龄

#include<bits/stdc++.h>
using namespace std;
int main(){
    float n,a[1001],cnt;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cnt+=a[i];
    }
    printf("%.2f",cnt/n);
    return 0;
}

ps:我会关注回答我的那位大神.


by hyl_____ @ 2024-09-01 22:33:20

@QDB1234 cnt没初始化


by qse_5858 @ 2024-09-01 22:34:03

@hyl_____ ?


by MSqwq @ 2024-09-01 22:34:09

初始化


by hyl_____ @ 2024-09-01 22:36:11

并且要用double


by hyl_____ @ 2024-09-01 22:37:08

#include<bits/stdc++.h>
using namespace std;
int main(){
    double n,a[1001],cnt=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cnt+=a[i];
    }
    printf("%.2lf",cnt/n);
    return 0;
}

by hyl_____ @ 2024-09-01 22:37:28

@QDB1234


by qse_5858 @ 2024-09-01 22:38:57

谢谢二位


by qse_5858 @ 2024-09-01 22:39:27

关注了


by chenzhishuo2012 @ 2024-09-03 13:46:53

#include<bits/stdc++.h>
using namespace std;
int n,a,sum;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a,sum+=a;
    printf("%0.2lf\n",1.0*sum/n);
    return 0;
}

|