A set of scores, a removing highest and lowest points and then averaged, and returned by the function

#include<stdio.h>
double fun(double a[],int n)
{
	double sum=0.0,max=a[0],min=a[0];
	int i;
	for(i=0;i<n;i++)
	{
		if(max<a[i])
			max=a[i];
		if(min>a[i])
			min=a[i];
		sum=sum+a[i];
	}
	sum=sum-min-max;
	return sum/(n-2);
}
void main()
{
	double aver,a[100];
	int i,n;
	printf("please input the count:");
	scanf("%d",&n);
	printf("please input the nums:");
	for(i=0;i<n;i++)
		scanf("%lf",&a[i]);
	aver=fun(a,n);
	printf("the aver is:%lf\n",aver);

}

  

Guess you like

Origin www.cnblogs.com/-slz-2/p/11275727.html
Recommended