首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
m个人的成绩存放在$eore数组中,请编写函数fun,它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指的数组中。 例如,当score数组中的数据为10、20、30、40、50、60、70、80、90时,函数返回的人
m个人的成绩存放在$eore数组中,请编写函数fun,它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指的数组中。 例如,当score数组中的数据为10、20、30、40、50、60、70、80、90时,函数返回的人
admin
2017-09-23
35
问题
m个人的成绩存放在$eore数组中,请编写函数fun,它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指的数组中。
例如,当score数组中的数据为10、20、30、40、50、60、70、80、90时,函数返回的人数应该是4,below中的数据应为10、20、30、40。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include < conio.h >
#include < stdio.h >
#include < string.h >
#include < stdlib.h >
int fun(int score[],int m,int below[])
{
}
void main()
{
FILE*wf;
int i,n,below[9];
2nt score[9]={10,20,30,40,50,60,70,80,90);
system("CLS");
n=fun(score,9,below);
print;f("\nBelow the average
SCOEe are:");
for(i=0;i < n;i++)
printf("%d",below
);
/******************/
wf=fopen("out.dat","w");
for(i=0;i < n;i++)
fprint:f(wf,"%d",below
);
fclose(wf);
/******************/
}
选项
答案
int fun (int score[ ],int m, int be { int i,j =0; float av =0 .0; for (i =0;i < m;i++) av=av+score[i]/m; /*.求平均值*/ for(i=0;i < m;i++) if (score[i] <av)/*如果分数低于平均分,则将此分数放入below数组中*/ below[j++]=score[i]; return j;/*返回低于平均分的人数*/ }
解析
要计算低于平均分的人数,首先应该求出平均分,然后通过for循环语句和if条件语句找出低于平均分的分数。该题第1个循环的作用是求出平均分av,第2个循环的作用是找出低于平均分的成绩记录并存入below数组中。
转载请注明原文地址:https://jikaoti.com/ti/lea0FFFM
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
诊断和改正程序中错误的工作通常称为()。
下面程序的输出结果是()。#include<stdio.h>main(){chara[]={’a’,’b’,’c’,’d’,’f’,’g’},*p;p=a;printf("%c\n",*p+4);}
以下叙述错误的是()。
下列关于函数的叙述中正确的是()。
先有两个C程序文件T18.c和myfun.c同在TC系统目录(文件夹)下,其中T18.c文件如下:#include<stdio.h>#include"myfun.C"main(){fun();printf("\n");}
下面程序运行后的输出结果是()。#include<stdio.h>main(){inta[5]={1,0,4,2,0},b[5]={1,2,3,4,5},i,s=0;for(i=0;i<5;i++)s=s+b[a[
若i、j已定义成int型,则以下程序段中内循环体的总执行次数是()。for(i=6;i>0;i--)for(j=0;j<4.j++){…}
以下程序的功能是:将输入的正整数按逆序输出。例如:若输入135,则输出531,请填空。#include<stdio.h>main(){intn,s;printf("Enteranumber:");scanf("%d",&n)
下面程序的功能是:计算1~20之间的奇数之和与偶数之和,请填空使程序功能完整。#include<stdio.h>main(){inta=0,b=0,c=0,i;for(i=0;i<=20;i+=2){a+=
以下程序中函数sort的功能足对a数组中的数据进行由大到小的排序voidsort(inta[],intn){inti,j,t;for(i=0;i<n-1;i++)for(j=i+1;j<n;j++)if(a[
随机试题
随机抽样
设函数在x=0连续,则k等于
下列膀胱肿瘤分期的声像图描述正确的有
当事人若对质量、价款等内容没有约定或约定不明确,则()。
甲、乙、丙三家承包单位,甲的资质等级最高,乙次之,丙最低。当三家单位实行联合共同承包时,应按( )单位的业务许可范围承揽工程。
某项目采用赢得值法进行综合分析后得到:BCWP>BCWS>ACWP,则()。
档案管理部门的人员管理会计档案,也属于会计岗位。()
新中国成立后,中国共产党把独立自主、自力更生运用到外交领域和经济建设方面,形成的方针、政策是()。
深圳青年歌手丛飞在8年时间内,捐资上百万元资助了很多贫困山区的失学儿童,而自己却身患癌症,负债17万元。有人这样评价他:“丛飞能够从帮助别人的过程中得到快乐。”丛飞的行为表明( )
Therearemanymedicalproblemsinthemodernsociety.Oneofthemostalarmingmedicalproblemsintheworldisa【1】diseasenam
最新回复
(
0
)