ewf8888 @ 2023-12-11 22:01:57
#include <stdio.h>
#include <math.h>
main ()
{
int n,i;
double a[330],sum=0,max=0,min=0,x,q,w;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%lf",&a[i]);
if(a[i]>max)
{
q=i;
max=a[i];
}
if(a[i]<min)
{
w=i;
min=a[i];
}
sum+=a[i];
}
x=(sum-max-min)/(n-2);
max=0;
for(i=1;i<=n;i++)
{
if(i!=q&&i!=w)
if(fabs(a[i]-x)>max)
max=fabs(a[i]-x);
}
printf("%.2lf %.2lf",x,max);
return 0;
}
by XyGetItRightAker @ 2023-12-28 13:59:35
max和min一开始都设为0?
min设为0那么就没有比它还要小的了,除非是负数,所以根本找不到最小值
by XyGetItRightAker @ 2023-12-28 14:00:40
可以把min设为0x3f3f3f3f
或者大一点的数
by ewf8888 @ 2024-01-18 17:17:24
@XyGetItRightAker 谢谢