编程题1,帮做下

来源:百度知道 编辑:UC知道 时间:2024/06/07 11:41:34
1。/* 求6个成绩的平均值及最大值 */
#include <stdio.h>
float fun ( float *a , int n ,float *max)
{

}
main()
{
float score[30]={ 80, 80.5, 81, 81.5, 82,82.5}, aver,max;
aver = fun( score,6,&max );
printf( "\nAverage score is: %5.2f\n", aver);
printf( "\nthe max score is: %5.2f\n", max);
}


#include <stdio.h>
float fun ( float *a , int n ,float *max)
{

int i=6;
float s=0.0;

for (i=0;i<6;i++)
{
s+=a[i];
if(a[i]>*max)
{
*max=a[i];
}

}

return s/6;
}
main()
{
float score[30]={ 80, 80.5, 81, 81.5, 82,82.5}, aver,max;
aver = fun( score,6,&max );
printf( "\nAverage score is: %5.2f\n", aver);
printf( "\nthe max score is: %5.2f\n", max);
}