liaoxiangkui @ 2024-01-06 18:07:35
#include<bits/stdc++.h>
using namespace std;
int main(){
float x,sum,n;
cin>>x;
for(int i=1;i<=x;i++){
cin>>n;
sum+=n;
}
printf("%0.2f",sum/=x);
}
by OIerWu_829 @ 2024-01-06 18:11:59
@liaoxiangkui
用 double
试试?
by Hacker_Cracker @ 2024-01-06 18:14:11
float x,sum,n;
好好的 double 摆着不用...
by _IOI_THANKFUL @ 2024-01-06 18:16:06
#include<bits/stdc++.h>
using namespace std;
double x,sum,n;
int main(){
cin>>x;
for(int i=0;i<x;i++){
cin>>n;
sum+=n;
}
cout<<fixed<<setprecision(2)<<sum/x;
}
用setprecision过了
by liaoxiangkui @ 2024-01-06 18:16:39
c++14(GCC 9)
by _IOI_THANKFUL @ 2024-01-06 18:17:08
@liaoxiangkui
by liaoxiangkui @ 2024-01-06 18:20:41
@_IOI_THANKFUL 我只是小菜,看不懂
by liaoxiangkui @ 2024-01-06 18:23:30
@wzj0829 用double可以了, 谢大佬