样例输出一直是负数,不知道是哪里错了,蒟蒻求助

P5726 【深基4.习9】打分

Mizuiro79 @ 2021-03-01 17:12:54

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,a[1001],a1,max,min,sum=0;
    double df;
    cin>>n>>a1;
    a1=max;
    a1=min;
    for(int i=2;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        if(a[i]>max) max=a[i];
        if(a[i]<min) min=a[i];
    }
    sum=sum-max-min;
    df=sum/(n-2);
    printf("%.2f",df);
    return 0;
 } 

by konjacq @ 2021-03-01 17:16:08

a1=max;
a1=min;
\Huge?

而且你sum有计算a_1


by _Emiria_ @ 2021-03-01 17:19:17

您的a1是什么意思呢


by 123456zmy @ 2021-03-01 17:33:20

a1=max;
a1=min;

改成

max=a1;
min=a1;
sum=a1;
df=sum/(n-2);

改成

df=(double)sum/(n-2);

by Mizuiro79 @ 2021-03-02 17:00:25

@123456zmy 谢谢


by zhou少 @ 2021-04-15 17:02:20

@江澂子、堯 数组应该是double 型


|