首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
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
33
问题
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://kaotiyun.com/show/yzxp777K
本试题收录于:
二级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");}
在下列选项中,没有构成死循环的程序段是()。
设变量均已正确定义,若要通过scanf("%d%c%d%c”,&a1,&e1,&a2,&c2);语句为变量a1和a2赋数值10和20,为变量c1和c2赋字符X和Y。下列所示的输入形式中正确的是(注:口代表空格字符)()。
下面程序的运行结果是()。y=5;x=14;y=((x=3*y,x+6),x-1);printf("x=%d,y=%d”,x,y);
下面程序中的数组a包括10个整数元素,从a中第二个元素起,分别将后项减前项之差存入数组b,并按每行4个元素输出数组b,请填空。main(){inta[10],b[10],i;for(i=0;i<10;i++)scanf("%d",
有以下程序:#include<string.h>inta=4;intf(intn){intt=0;staticinta=5;if(n%2){inta=6;t++=a++;}else{inta
字符串"\\"ABCDEF\"\\”的长度是()。
若变量都已正确说明,则以下程序段输出结果为()。#include<stdio.h>main(){chara=’a’;intb=2;printf(a>b?”***a=%d":"###b=%d",a,B;
下面程序的功能是:从输入的正整数中选3个数进行输出,要求这些数都是2的倍数,请填空。main(){inta,i=0;scanf("%d",&A);do{if(a>0&&a%2==0){printf("%d
随机试题
DXC所交换的是由多路信号构成的群信号,基本上保持()连接。
FDDI标准的环路最大长度为_______。
透视检查的优点不包括
下列各物质的化学键中,只存在σ键的是()。
在下列净现值与折现率关系的描述中,正确的是()。
读世界大洲、大洋分布图(图4),回答问题。 图中字母“P”表示的纬线是____。
A.血管损伤B.神经损伤C.骨折延迟愈合D.骨筋膜室综合征胫骨下1/3骨折易导致
有某数据库系统在运行过程中发生了系统故障,发生故障时正在运行事务t1和t2。进行故障恢复时,在日志文件中发现有t1的事务开始记录而没有结束记录,有t2的开始记录和结束记录,但t2对数据库的修改还没有写到数据库中,从检查点开始正向扫描日志文件______。
A、 B、 C、 C
"Equalpayforequalwork"isaphraseusedbytheAmericanwomenwhofeelthattheyareunfairlytreatedbysociety.Theysayi
最新回复
(
0
)