zian123 @ 2024-01-04 15:35:12
#include <stdio.h>
int main() {
int n, i, x;
double sum = 0;
scanf("%d", &n);
for (i = 0; i <= n; i++) {
scanf("%d\n", &x);
sum += x;
}
printf("%0.2f",sum / n);
}
by Rieman_sum @ 2024-01-04 15:36:06
@zian123 循环改为for(int i=0;i<n;i++)
by Rieman_sum @ 2024-01-04 15:36:42
https://www.luogu.com.cn/record/141879167
by jacob_zhou @ 2024-01-04 16:09:06
#include <stdio.h>
int main() {
int n, i, x;
double sum = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d\n", &x);
sum += x;
}
printf("%0.2f",sum*1.0 / n);
}
// 循环多了一次, 0到小于等于n是循环n+1次,改成从1开始就行了