【计算机类职业资格】二级C语言-48及答案解析.doc

上传人:fuellot230 文档编号:1325389 上传时间:2019-10-17 格式:DOC 页数:2 大小:35KB
下载 相关 举报
【计算机类职业资格】二级C语言-48及答案解析.doc_第1页
第1页 / 共2页
【计算机类职业资格】二级C语言-48及答案解析.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 C 语言-48 及答案解析(总分:28.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:-1.00)1.请补充函数 fun(),该函数的功能是:计算 NN 维矩阵元素的方差,结果由函数返回。维数 N 在主函数中输入。例如: (分数:-1.00)填空项 1:_二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:从 m 个学生的成绩中统计出低于平均分的学生人数,人数由函数值返回,平均分存放在形参 aver 所指的存储单元中。例如输入 8 名学生的成绩: 60 70 80 90 65 75 85 95 则低于平均分的学生人数为 4(平

2、均分为 77.5)。实际输入时学生数以回车键作为结束,成绩与成绩之间也与回车键作为分隔。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #ineludestdlib.h #includestdio.h #includeconio.h #define M 20 int proc (float *s, int n, float * aver) /*found* int ave, t=0; int count=0, k, i; for(k=0; kn; k+) t+=sk; ave=t/n; for(i=0; in;

3、i+) /*found* if(siave) count+; /*found* aver=ave; return count; void main() float stu30, aver; int m, i; system(“CLS“); printf(“/nPlease enter m: “); scanf(“%d“, m); printf(“/nPlease enter%d mark: /n“, m); for(i=0; im; i+) scanf(“%f“, stu+i); printf(“/nThe number of students: %d/n“, proc(stu, m, ave

4、r); printf(“Ave=%f/n“, aver); (分数:30.00)填空项 1:_三、B编程题/B(总题数:1,分数:-1.00)3.编写函数 fun,其功能是计算: (分数:-1.00)_二级 C 语言-48 答案解析(总分:28.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:-1.00)1.请补充函数 fun(),该函数的功能是:计算 NN 维矩阵元素的方差,结果由函数返回。维数 N 在主函数中输入。例如: (分数:-1.00)填空项 1:_ (正确答案:【1】int aN 【2】s/(n*n) 【3】sqrt(f))解析:解析 填空 1;由主函数 main(

5、)中对函数 fun()的调用格式,可以知道,函数 fun()的第一个参数是 NN 的二维整型数组。填空 2:平均值等于所有元素的累加和除以个数。填空 3;根据公式,方差 sd等于对变量 f 开平方,这里注意对数学库函数的调用。二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:从 m 个学生的成绩中统计出低于平均分的学生人数,人数由函数值返回,平均分存放在形参 aver 所指的存储单元中。例如输入 8 名学生的成绩: 60 70 80 90 65 75 85 95 则低于平均分的学生人数为 4(平均分为 77.5)。实际输入时学生数以回车键作为结束,

6、成绩与成绩之间也与回车键作为分隔。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #ineludestdlib.h #includestdio.h #includeconio.h #define M 20 int proc (float *s, int n, float * aver) /*found* int ave, t=0; int count=0, k, i; for(k=0; kn; k+) t+=sk; ave=t/n; for(i=0; in; i+) /*found* if(siave) coun

7、t+; /*found* aver=ave; return count; void main() float stu30, aver; int m, i; system(“CLS“); printf(“/nPlease enter m: “); scanf(“%d“, m); printf(“/nPlease enter%d mark: /n“, m); for(i=0; im; i+) scanf(“%f“, stu+i); printf(“/nThe number of students: %d/n“, proc(stu, m, aver); printf(“Ave=%f/n“, aver

8、); (分数:30.00)填空项 1:_ (正确答案:(1)错误:int ave, t=0; 正确:float ave, t=0.0; (2)错误:if(siave) 正确:if(siave) (3)错误:aver=ave; 正确:*aver=ave;)解析:解析 由程序可知变量 ave 和 t 中分别存放的是学生的平均分数和分数的总和,都是 float 型数据。因此 int ave, t=0;应改为 float ave, t=0.0;题目要求统计出低于平均分数的学生人数,因此if(siave)应改为 if(siave);平均分数是通过指针变量传递回主函数的,因此 aver=ave;改为*av

9、er=ave。三、B编程题/B(总题数:1,分数:-1.00)3.编写函数 fun,其功能是计算: (分数:-1.00)_正确答案:(double fun(int m) int i; double s=0.0; for(i=1;i=m;i+) s=s+log(i);/*计算 s=ln(1)+ln(2)+ln(3)+ln(m)*/ return sqrt(s);/*对 s 求平方根并返回*/ )解析:解析 题目要求写出程序实现数学表达式的功能,需要用 for 循环计算累加的结果,调用 sqrt 函数实现求平方根。循环变量的范围是 1m,每次循环都进行一次累加求和。需要特别注意的是,log 函数的形式参数为 double 型变量,用于循环的计数变量为整数,所以必须强制转换。最后返回所求出的平方根。

展开阅读全文
相关资源
猜你喜欢
  • EN ISO 23747-2015 en Anaesthetic and respiratory equipment - Peak expiratory flow meters for the assessment of pulmonary function in spontaneously breathing humans《麻醉和呼吸设备 自然呼吸的人肺部.pdf EN ISO 23747-2015 en Anaesthetic and respiratory equipment - Peak expiratory flow meters for the assessment of pulmonary function in spontaneously breathing humans《麻醉和呼吸设备 自然呼吸的人肺部.pdf
  • EN ISO 23753-1-2011 en Soil Quality - Determination of dehydrogenase activity in soil - Part 1 Method using triphenyltetrazolium chloride (TTC)《土质 土壤中脱氢酶活性的测定 第1部分 采用三苯基四唑嗡化氯(TTC)进.pdf EN ISO 23753-1-2011 en Soil Quality - Determination of dehydrogenase activity in soil - Part 1 Method using triphenyltetrazolium chloride (TTC)《土质 土壤中脱氢酶活性的测定 第1部分 采用三苯基四唑嗡化氯(TTC)进.pdf
  • EN ISO 23753-2-2011 en Soil Quality - Determination of dehydrogenase activity in soils - Part 2 Method using iodotetrazolium chloride (INT)《土壤质量 土壤中脱氢酶活性的测定 第2部分 使用氯化碘四唑法(INT)(ISO2.pdf EN ISO 23753-2-2011 en Soil Quality - Determination of dehydrogenase activity in soils - Part 2 Method using iodotetrazolium chloride (INT)《土壤质量 土壤中脱氢酶活性的测定 第2部分 使用氯化碘四唑法(INT)(ISO2.pdf
  • EN ISO 23771-2015 en Textile machinery - Guide to the design of textile machinery for reduction of the noise emissions《纺织机械 减少噪音污染用纺织机械的设计指南(ISO 23771 2015)》.pdf EN ISO 23771-2015 en Textile machinery - Guide to the design of textile machinery for reduction of the noise emissions《纺织机械 减少噪音污染用纺织机械的设计指南(ISO 23771 2015)》.pdf
  • EN ISO 23907-2012 en Sharps injury protection - Requirements and test methods - Sharps containers《锐器损伤防护 试验方法和要求 利器盒》.pdf EN ISO 23907-2012 en Sharps injury protection - Requirements and test methods - Sharps containers《锐器损伤防护 试验方法和要求 利器盒》.pdf
  • EN ISO 23908-2013 en Sharps injury protection - Requirements and test methods - Sharps protection features for single-use hypodermic needles introducers for catheters and needles u.pdf EN ISO 23908-2013 en Sharps injury protection - Requirements and test methods - Sharps protection features for single-use hypodermic needles introducers for catheters and needles u.pdf
  • EN ISO 23910-2017 en Leather - Physical and mechanical tests - Measurement of stitch tear resistance《皮革 物理和机械试验-缝合撕裂电阻测量(ISO 23910 2017)》.pdf EN ISO 23910-2017 en Leather - Physical and mechanical tests - Measurement of stitch tear resistance《皮革 物理和机械试验-缝合撕裂电阻测量(ISO 23910 2017)》.pdf
  • EN ISO 23913-2009 en Water quality - Determination of chromium(VI) - Method using flow analysis (FIA and CFA) and spectrometric detection《水质 铬的测定(IV) 流动分析(CFA和FIA)法和光谱测定法》.pdf EN ISO 23913-2009 en Water quality - Determination of chromium(VI) - Method using flow analysis (FIA and CFA) and spectrometric detection《水质 铬的测定(IV) 流动分析(CFA和FIA)法和光谱测定法》.pdf
  • EN ISO 23936-1-2009 en Petroleum petrochemical and natural gas industries - Non-metallic materials in contact with media related to oil and gas production - Part 1 Thermoplastics《石.pdf EN ISO 23936-1-2009 en Petroleum petrochemical and natural gas industries - Non-metallic materials in contact with media related to oil and gas production - Part 1 Thermoplastics《石.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1