lvyan2024 @ 2025-01-11 13:18:03
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int n;
long double sum=0;
cin>>n;
int a[n];
for (int i = 0; i < n; ++i) {
cin>>a[i];
}
for (int i = 0; i < n; ++i) {
sum+=a[i];
}
printf("%.2Lf",sum/n);
}
by chenyuan3 @ 2025-01-11 13:30:11
"%.2Lf"
改为 "%.2lf"
(l
不大写)@lvyan2024
by pjh0625 @ 2025-01-11 13:56:39
@lvyan2024
你的代码改了“%.2lf”也应该过不了
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
scanf("%d",&n);
int age;
double sum=0,f=0;
int i;
for(i=0;i<n;i++)
{
scanf("%d",&age);
sum=sum+age;
}
f=sum/n;
printf("%.2lf",f);
return 0;
}
by xty0627 @ 2025-01-11 14:24:39
**printf("%.2Lf",sum/n);** 改为 printf("%.2f",sum/n); 具体代码为:
#include<bits/stdc++.h>
int main(){
int n,x;
double sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&x);
sum+=x;
}
printf("%.2f",sum/n);
return 0;
}
by Whr___114514 @ 2025-01-11 14:29:20
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int a;
double b;
cin>>n;
for(int i=0;i<n;i++){
cin>>a;
b+=a;
}
b/=n;
cout<<setprecision(2)<<fixed<<b;
return 0;
}
我就是习惯用iomanip,iostream。