Yjkaixuexi @ 2024-11-16 19:37:56
B2055 均值 为啥全错 大佬995 devc++没问题
#include<bits/stdc++.h>
using namespace std;
int main(){
float n,b=0;
int a[105];
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
b=b+a[i];
}
float w=b/n;
cout<<b<<" "<<w;
}
by xjhjtz0320 @ 2024-11-17 10:51:00
@Yjkaixuexi 已AC
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
double a=0,ans=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a;
ans+=a;
}
ans/=n*1.0000;
printf("%.4lf",ans);
}
可以不用数组,首先一边读入一边累加,然后除n,乘1.0000其实可不加 然后用printf输出,注意输出格式
by VVinky_ @ 2024-11-20 23:18:05
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int N;
double sum;
scanf("%d", &N);
for (int i = 1; i <= N; i ++)
{
double j;
scanf("%lf", &j);
sum += j;
}
printf("%.4lf", sum / N);
return 0;
}