例题:请编写一个函数fun,它的功能是:计算n门课程的平均分,计算结果作为函数值返回。
例如,若有5门课程的成绩是88、92、80、61.5、55;则函数的值为75.30。
请勿改动主函数main与其它函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
代码如下:
#include<stdio.h>
float fun(float*b,int m)
{
float ave=0.0;
int i;
for(i=0;i<m;i++)
ave+=b[i];
ave/=m;
return ave;
}
main()
{
float s[10]={
88,92,80,61.5,55},aver;
FILE*out;
aver=fun(s,5);
printf("\nAverage is:%5.2f\n",aver);
out=fopen("outfile.dat","w");
fprintf(out,"%5.2f",aver);
fclose(out);
}
输出运行窗口如下:
越努力越幸运!
加油,奥力给!!!