c语言求助,一直想不明白哪里错了

B2095 白细胞计数

Don_Su @ 2023-01-31 15:58:42

#include<stdio.h>
#include<math.h>
void sort(double *ar,int n);
int main(void)
{   int n,i;
    double j,s=0;
    scanf("%d",&n);
    double a[n];
    for(i=0;i<n;i++)
    {scanf("%lf",&a[i]);
     s+=a[i];}
     sort(a,n);
     j=(s-a[0]-a[n-1])/(n-2);
     printf("%.2lf",j);
     if(fabs(j-a[1])>fabs(j-a[n-2]))
        printf("%.2lf",fabs(j-a[1]));
     else
        printf(" %.2lf",fabs(j-a[n-2]));    
    return 0;
}
void sort(double *a,int n)
{int i,j;
double v;
for(i=0;i<n-1;i++)
    for(j=i+1;j<n;j++)
    {if(a[i]>a[j])
     {v=a[i];
     a[i]=a[j];
     a[j]=v;}
    }
}

by 编码落寞 @ 2023-01-31 16:23:45

@Don_Su

  printf("%.2lf",fabs(j-a[1]));

前面加个空格试试


by Don_Su @ 2023-01-31 17:33:25

@编码落寞 离谱(捂脸) 感谢大佬


|