Statistical average, the highest score and the highest number of points

Please write a function fun, function is the function: the statistics of several student grade point average, the highest number of points and get the highest score.

Function interface definition:

float fun(float array[],int n);

Wherein n and array parameters are passed in user. Function shall statistical average score array of secondary school students array, the highest score and the highest number of points, the function returns the average score, the highest score and the highest number of points stored in a global variable and J Max.

Referee test program Example:

#include <stdio.h>
float Max=0;
int J=0;
float fun(float array[],int n);
int main()
{
float  a[10],ave;
int i=0;
for(i=0;i<10;i++)
scanf("%f",&a[i]);
ave=fun(a,10);
printf("ave=%.2f\n",ave);
printf("max=%.02f\n",Max);
printf("Total:%d\n",J);
return 0;
 }

/* 请在这里填写答案 */

Sample input:

84 75 86 59 25 94 76 84 15 65

Sample output:

ave=66.30
max=94.00
Total:1

float fun(float array[],int n)
{
	double f;
	int i,j=0;
	for(i=0;i<n;i++)
		f+=array[i];
	f=f/n;
	for(i=1;i<n;i++)
	{
		if(array[j]<array[i])
			j=i;
	}
	Max=(int)array[j];
	for(i=0;i<n;i++)
		if(Max==(int)array[i])
			J++;
	return f;
}
Published 44 original articles · won praise 26 · views 213

Guess you like

Origin blog.csdn.net/Noria107/article/details/104213213