调用函数FUN功能是:计算N门课程的平均分,计算结果作为函数值返回.
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/02 09:41:48
调用函数FUN功能是:计算N门课程的平均分,计算结果作为函数值返回.
主函数中N为定义,N的数值由输入的课程数来决定,
把主函数和调用函数一起写出来,
主函数中N为定义,N的数值由输入的课程数来决定,
把主函数和调用函数一起写出来,
/*
班级人数 :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;
}
班级人数 :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;
}
调用函数FUN功能是:计算N门课程的平均分,计算结果作为函数值返回.
请用c语言编写一个函数fun功能是:计算n门课程的平均分,计算结果作为函数值返回
急用:c语言,设计一个fun函数,它的功能是计算n门课程的平均值,并将计算所得结果作为函数值返回,
C语言 计算n门课程的平均值,计算结果作为函数值返回.
输入一个正整数n(n≤10),编写函数fun(a,n),它的功能是计算n门课程的平均分,
编写函数fun,函数的功能是:根据以下公式计算s,计算结果作为函数值返回;m通过形参传入.
1. 编写一个函数fun,然后设计主函数调用函数fun.函数fun的功能是:求两数平方根之和,作为函数值返回.
编写fun,其功能是:根据以下公式计算s,将结果作为函数值返回;n通过形参传入. 帮我看看我哪里出问题了?
C语言:在score数组存放有m个成绩,在函数fun中计算平均分,再将低于平均分的人数作为函数值返回,
函数fun的功能是:根据以下公式计算并返回S,n通过形参传入,n的值
设计函数fun实现计算n的阶乘n!,其中n没函数参数;在函数中调用fun函数,来实现计算1到5的阶乘功能并将结果按下面格
请编写函数fun,其功能是:计算并输出3到n之间的所有素数的平方根之和.在主函数中调用函数fun,并输出结果.