0分

B2054 求平均年龄

jiangjun12345 @ 2024-07-29 21:30:14

include<bits/stdc++.h>

using namespace std; int main(){ int i,n; float s,x; cin>>n; for(i=1;i<=n;i++){ cin>>x; s=s+x; } s=s/n; printf("%.4f",s); return 0; }


by Grammar__hbw @ 2024-07-29 21:31:28

希望更丰富的展现?使用 Markdown、KaTeX。


by Ke9_qux @ 2024-07-29 21:34:48

小数点后两位,您写的是.4f


by Mr_yang1 @ 2024-07-29 21:36:50

注意位数

#include<bits/stdc++.h>
using namespace std;
int main(){
    double n,s=0,ds;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>ds;
        s+=ds;
    }
    printf("%.2f",s/n);
} 

by jinrunsen @ 2024-08-21 15:19:46

#include<bits/stdc++.h>
using namespace std;
int main(){
    int i,n;
    double s,x;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>x;
        s=s+x;
    }
    s=s/n;
    printf("%.2f",s);
    return 0;
    }

by jinrunsen @ 2024-08-21 15:22:33

注意


|