首页 > 编程语言 > 详细

C语言参数传递,数组参数传递,切记传递的根本

时间:2019-08-29 18:09:52      阅读:101      评论:0      收藏:0      [点我收藏+]

#include <stdio.h>
#define M 10 //总人数

/*m个人的成绩存放在score数组中
请编写函数fun,它的功能是:将低于平均分的人数作为函数值返回,
将低于平均分的分数放在below所指定的数组中。
函数原型: int fun(int score[],int m,int below[])
此题为06年南开大学研究生复试上机题
*/
int fun(int score[],int m, int below[])
{
int num_pingjunfen=0;
int num_zongfen=0;
int i=0,j=0,n=0;

for(i=0;i<m;i++)
{
num_zongfen=num_zongfen+score[i];
}
num_pingjunfen=num_zongfen/m;
printf("平均分为%d\n",num_pingjunfen);

for(i=0;i<M;i++)
{
if (score[i]<num_pingjunfen)
below[n++]=score[i];
}

for(i=0;i<n;i++)
{
printf("低于平均分的名单%d 得分:%d \n",i+1,below[i]);
}

return n;


}

main()
{
int j=0;
int score[M]={10,1,10,5,2,10,10,10,5,0};
int below[M];
j= fun(score,M,below);
printf("低于平均分的人数共计:%d\n",j);

}

C语言参数传递,数组参数传递,切记传递的根本

原文:https://www.cnblogs.com/qianrushi1/p/11431178.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!