HEROBRINEH @ 2024-03-10 12:57:19
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n]={0};
for(int i=0;i<n;i++){
cin>>a[i];
}
float ave=0;
for(int j=0;j<n;j++){
ave=ave+a[j];
}
ave=ave/n;
cout<<fixed<<setprecision(2)<<ave;
return 0;
}
by fanjiayu666 @ 2024-03-10 13:15:18
额,你这个代码
cpp:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
double h=0,z;
cin>>a;
for(int i=0;i<a;i++){
cin>>z;
h+=z;
}
h/=a;
printf("%lf",h);
return 0;
}
by fanjiayu666 @ 2024-03-10 13:17:36
printf("%lf",h);
错了
printf("%.2lf",h);
by Mr_Clock @ 2024-04-19 17:03:58
@楼主 你没保留两位小数dio
by Rb3f @ 2024-06-22 15:41:49
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
double h=0,z;
cin>>a;
for(int i=0;i<a;i++){
cin>>z;
h+=z;
}
h/=a;
printf("%lf",h);
return 0;
}
by joe_001 @ 2024-08-08 17:21:52
#include<bits/stdc++.h>
using namespace std;
long long n,a[10001];
double k;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
k=a[1];
for(int i=2;i<=n;i++)
k+=a[i];
k=k*1.0/n;
cout<<fixed<<setprecision(2)<<k<<endl;
return 0;
}