功能:计算n门课程的平均值,计算结果作为函数值返回。
例如:若有5门课程的成绩是:92,76,69,58,88,则函数的值为76.600000。
#include <stdio.h>
void wwjt();
float fun(int a[],int n)
{
/**********Program**********/
/********** End **********/
}
main()
{
int a[]={92,76,69,58,88};
printf("y=%f\n",fun(a,5));
wwjt();
}
void wwjt()
{
FILE *IN,*OUT;
int iIN[10],i,j;
float fOUT;
IN=fopen("in.dat","r");
if(IN==NULL)
{
printf("Please Verify The Currernt Dir..it May Be Changed");
}
OUT=fopen("out.dat","w");
if(OUT==NULL)
{
printf("Please Verify The Current Dir.. it May Be Changed");
}
for(j=0;j<5;j++)
{
for(i=0;i<5;i++)
fscanf(IN,"%d",&iIN[i]);
fOUT=fun(iIN,5);
fprintf(OUT,"%f\n",fOUT);
}
fclose(IN);
fclose(OUT);
}
登录后提交答案