题解 | #统计成绩#
统计成绩
https://www.nowcoder.com/practice/cad8d946adf64ab3b17a555d68dc0bba
为什么这种不行呢
#include<stdio.h>
int main()
{
float a[100],avg=0,min,max;
int i,n;
scanf("%d",&n);
for (i=0;i<n;i++)
{
scanf("%f",&a[i]);
max=min=a[0];
if(a[i]>max)
{
max=a[i];
}
if(a[i]<min)
{
min=a[i];
}
avg+=a[i];
}
printf("%.2f %.2f %.2f",max,min,avg/n);
return 0;
}
int main()
{
float a[100],avg=0,min,max;
int i,n;
scanf("%d",&n);
for (i=0;i<n;i++)
{
scanf("%f",&a[i]);
max=min=a[0];
if(a[i]>max)
{
max=a[i];
}
if(a[i]<min)
{
min=a[i];
}
avg+=a[i];
}
printf("%.2f %.2f %.2f",max,min,avg/n);
return 0;
}