调用函数FUN功能是:计算N门课程的平均分,计算结果作为函数值返回.

问题描述:

调用函数FUN功能是:计算N门课程的平均分,计算结果作为函数值返回.
主函数中N为定义,N的数值由输入的课程数来决定,
把主函数和调用函数一起写出来,
1个回答 分类:综合 2014-09-22

问题解答:

我来补答
/*
班级人数 :60
课程数 :12
第1门课平均成绩是 :77.77
第2门课平均成绩是 :76.10
第3门课平均成绩是 :73.94
第4门课平均成绩是 :77.88
第5门课平均成绩是 :76.91
第6门课平均成绩是 :75.07
第7门课平均成绩是 :75.85
第8门课平均成绩是 :77.29
第9门课平均成绩是 :77.51
第10门课平均成绩是 :76.34
第11门课平均成绩是 :77.94
第12门课平均成绩是 :78.41
Press any key to continue
*/
#include
#include
#include
double Average(double a[],int m) {
double sum = 0.0;
int i;
for(i = 0; i < m; ++i)
sum += a[i];
return sum/m;
}
int main() {
double **scores;
int i,j,n,m;
printf("班级人数 :");
scanf("%d",&m);
printf("课程数 :");
scanf("%d",&n);
scores = (double **)malloc(sizeof(double *) * n);;
srand((unsigned)time(NULL));
for(i = 0; i < n; ++i) {
scores[i] = (double *)malloc(sizeof(double) * m);
for(j = 0; j < m; ++j)
scores[i][j] = 0.01 * (rand()%4401 + 5600);
}
for(i = 0; i < n; ++i) {
printf("第%d门课平均成绩是 :%.2lf\n",i + 1,Average(scores[i],m));
free(scores[i]);
}
return 0;
}
 
 
展开全文阅读
剩余:2000
下一页:格子里面填一下