tanchen123 @ 2024-11-07 20:50:57
#include <stdio.h>
int main()
{
int n = 0;
scanf("%d", &n);
int num[] = { 0 };
int i = 0;
double sum = 0.0;
int max, min;
for (int i = 0;i < n;i++)
{
scanf("%d", &num[i]);
sum += num[i];
}
max = min = num[0];
for (int i = 0;i < n;i++)
{
if (num[i] > max)
{
max = num[i];
}
if (num[i] < min)
{
min = num[i];
}
}
sum = (sum-max-min) / (n-2);
printf("%.2llf\n",sum);
return 0;
}
by Civilight_Eterna @ 2024-11-07 20:54:04
@tanchen123 把输出的两个l去掉一个
by fzy1139950253 @ 2024-11-07 22:36:33
看到int num[] = { 0 };这一行,你没有指定数组的大小,这会导致默认的数组大小是后面初始化的长度,也就是1,导致后面越界访问。可以在[]写个数字1010。
看到printf("%.2llf\n",sum);这一行,多写了一个l
经过验证,这样就ac了
by tanchen123 @ 2024-11-07 23:59:12
@fzy1139950253 难怪,感谢大佬 !!