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

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

1、二级 C 语言-277 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是计算下式 直到 (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.给定程序中函数 fun 的功能是:求出以下分数序列的前 n 项之和。和值通过函数值返回到 main 函数。 (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写一个函数 fun,它的功能是:求出一个 2M 整型二维数组中最大元素的值,并将此值返回调用函数。 请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的

2、花括号中填入你编写的若干语句。 给定源程序: #includestdio.h #defineM 4 int fun(int aM) main() int arr2M=5, 8, 3, 45, 76, -4, 12, 82; printf(“max=%d/n“, fun(arr); (分数:40.00)_二级 C 语言-277 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是计算下式 直到 (分数:30.00)解析:(1)3.0 或(double)3 (2) (3)(t+1) 解析 填空 1:变量 x 定义为

3、 double 类型,而运算符“/“后面是整型数,所以给 x 赋值时,需要注意数据类型,此处不能将 3.0 写成 3。 填空 2:while 循环语句的循环条件,根据题意确定循环变量应大于 1e-3,因此此处应填“。 填空 3:表达式的通项是(2*i+1)/(2*i)2,由于程序中已定义 t=2*i,所以此处应该填写(t+1)。二、程序改错题(总题数:1,分数:30.00)2.给定程序中函数 fun 的功能是:求出以下分数序列的前 n 项之和。和值通过函数值返回到 main 函数。 (分数:30.00)解析:(1)double fun(int n) (2)s=s+(double)a/b; 解析

4、 (1)由语句“return(s)“和变量 s 定义为 double 数据类型可知,该函数定义时其类型标识符为 double 类型。 (2)注意数据类型 double 的书写格式。三、程序设计题(总题数:1,分数:40.00)3.请编写一个函数 fun,它的功能是:求出一个 2M 整型二维数组中最大元素的值,并将此值返回调用函数。 请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #includestdio.h #defineM 4 int fun(int aM) main() int arr2M=5, 8, 3, 45, 76

5、 -4, 12, 82; printf(“max=%d/n“, fun(arr); (分数:40.00)_正确答案:()解析:int fun(int aM) int i, j, max=a00; for(i=0; i2; i+) for(j=0; jM; j+) if(maxaij) max=aij; return max; 解析 此类求最大值或最小值的问题,我们可以采用逐个比较的方式,要求对数组中所有元素遍历一遍,并且从中找出数组最大值或最小值。首先定义变量 max 存放数组中的第一个元素的值,然后利用 for循环逐个找出数组中的元素,并与 max 比较,如果元素值大于 max,则将该值赋于 max,循环结后 max 的值即为数组最大值,最后将该值返回。

展开阅读全文
相关资源
猜你喜欢
  • BS PD CEN TR 15177-2006 Testing the freeze-thaw resistance of concrete — Internal structural damage《混凝土抗冻融性能试验 内部结构损坏》.pdf BS PD CEN TR 15177-2006 Testing the freeze-thaw resistance of concrete — Internal structural damage《混凝土抗冻融性能试验 内部结构损坏》.pdf
  • BS PD CEN TR 15193-2-2017 Energy performance of buildings Energy requirements for lighting Explanation and justification of EN 15193-1 Module M9《建筑物能源性能 照明的能源需求 EN 15193-1.pdf BS PD CEN TR 15193-2-2017 Energy performance of buildings Energy requirements for lighting Explanation and justification of EN 15193-1 Module M9《建筑物能源性能 照明的能源需求 EN 15193-1.pdf
  • BS PD CEN TR 15232-2-2016 Energy performance of buildings Accompanying TR prEN 15232-1 2015 Modules M10-4 5 6 7 8 9 10《建筑的能源性能 引用TR prEN 15232-1-2015 M10-4 5 6 7 8 9 10模块》.pdf BS PD CEN TR 15232-2-2016 Energy performance of buildings Accompanying TR prEN 15232-1 2015 Modules M10-4 5 6 7 8 9 10《建筑的能源性能 引用TR prEN 15232-1-2015 M10-4 5 6 7 8 9 10模块》.pdf
  • BS PD CEN TR 15276-1-2009 Fixed firefighting nsystems — Condensed naerosol extinguishing nsystems nPart 1 Requirements and test methods nfor components《固定的消防系统 浓缩气溶胶灭火系统 .pdf BS PD CEN TR 15276-1-2009 Fixed firefighting nsystems — Condensed naerosol extinguishing nsystems nPart 1 Requirements and test methods nfor components《固定的消防系统 浓缩气溶胶灭火系统 .pdf
  • BS PD CEN TR 15276-2-2009 Fixed firefighting nsystems — Condensed naerosol extinguishing nsystems nPart 2 Design installation and nmaintenance《固定式消防系统 浓缩气溶胶灭火系统 第2部分 设计、安.pdf BS PD CEN TR 15276-2-2009 Fixed firefighting nsystems — Condensed naerosol extinguishing nsystems nPart 2 Design installation and nmaintenance《固定式消防系统 浓缩气溶胶灭火系统 第2部分 设计、安.pdf
  • BS PD CEN TR 15278-2006 Workplace exposure - Strategy for the evaluation of dermal exposure《作业场所暴露 经皮暴露的评估策略》.pdf BS PD CEN TR 15278-2006 Workplace exposure - Strategy for the evaluation of dermal exposure《作业场所暴露 经皮暴露的评估策略》.pdf
  • BS PD CEN TR 15281-2006 Guidance on Inerting for the Prevention of Explosions《爆炸预防用惰化导则》.pdf BS PD CEN TR 15281-2006 Guidance on Inerting for the Prevention of Explosions《爆炸预防用惰化导则》.pdf
  • BS PD CEN TR 15298-2006 Foodstuffs — Sample comminution for mycotoxins analysis — Comparison between dry milling and slurry mixing《食品 真菌毒素分析的抽样粉碎 干磨和泥浆混合的对比》.pdf BS PD CEN TR 15298-2006 Foodstuffs — Sample comminution for mycotoxins analysis — Comparison between dry milling and slurry mixing《食品 真菌毒素分析的抽样粉碎 干磨和泥浆混合的对比》.pdf
  • BS PD CEN TR 15310-1-2006 Characterization of waste — Sampling of waste materials — nPart 1 Guidance on selection and application of criteria for sampling under various c.pdf BS PD CEN TR 15310-1-2006 Characterization of waste — Sampling of waste materials — nPart 1 Guidance on selection and application of criteria for sampling under various c.pdf
  • 相关搜索

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

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