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

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

1、二级 C 语言机试-247 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)请在函数 proc()的横线上填写若干表达式,使从键盘上输入一个整数 n,输出斐波那契数列的前 n 个数。斐波那契数列是一整数数列,该数列自第 3 项开始,每个数等于前面两个数之和,即0,1,1,2,3,5,8,13,21,34,55,。注意:部分源程序已给出。请勿改动主函数 main 和其他函数中的任何内容。试题程序:#includestdio.hint procint n;void main()int i, n=0;printf(“please enter n: “)

2、scanf(“%d“, n);for(i=0; in; i+)printf(“%d“, proc(i);int proc(int n)if( (1) )return 0;elseif( (2) )return 1;elsereturn (3) ;(分数:30.00)填空项 1:_填空项 1:_填空项 1:_二、改错题(总题数:1,分数:30.00)1.下列给定程序中函数 fun 的功能是按以下递归公式求函数值。例如,当给 n 输入 3 时,函数值为 60;当给 n 输入 6 时,函数值为 480。请修改程序中的错误,使它能得到正确结果。注意:不要改动 main()函数,不得增行或删行,也不得

3、更改程序的结构。试题程序:#includestdio.h/*found*fun(int n);int j;/*found*if(n=1)j=15;elsej=fun(n=1) *2;return(j);void main()int n;printf(“Enter n: “);scanf(“%d“, printf(“The result: %d/n/n“, fun(n);(分数:30.00)填空项 1:_三、编程题(总题数:1,分数:40.00)2.编写函数 proc(),函数的功能是:根据以下公式计算 s,计算结果作为函数值返回,m 通过形参传入。S=1+1/(1+2)+1/(1+2+3)+1

4、/(1+2+3+m)例如,若 n 的值为 11 时,函数的值为 1.833333。注意:部分源程序已给出。请勿改动主函数 main 和其他函数中的任何内容。试题程序:#includestdlib.h#includeconio.h#includestdio.h#includestring.hfloat proc(int m)void main()int m;float s;system (“CLS“);printf(“/nPlease enter M: “);scanf(“%d“, s=proc(m);printf(“The result is: %f/n“, s);(分数:40.00)_二级

5、C 语言机试-247 答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)请在函数 proc()的横线上填写若干表达式,使从键盘上输入一个整数 n,输出斐波那契数列的前 n 个数。斐波那契数列是一整数数列,该数列自第 3 项开始,每个数等于前面两个数之和,即0,1,1,2,3,5,8,13,21,34,55,。注意:部分源程序已给出。请勿改动主函数 main 和其他函数中的任何内容。试题程序:#includestdio.hint procint n;void main()int i, n=0;printf(“please enter n: “);sca

6、nf(“%d“, n);for(i=0; in; i+)printf(“%d“, proc(i);int proc(int n)if( (1) )return 0;elseif( (2) )return 1;elsereturn (3) ;(分数:30.00)填空项 1:_ (正确答案:n=0)解析:填空项 1:_ (正确答案:n=1)解析:填空项 1:_ (正确答案:proc(n-1)+proc(n-2))解析:解析 由斐波那契数列的定义可知,该数列中有两个特殊项。当 n 为 0 时,其值为 0,当 n 为 1时,其值为 1。因此,1处填 n=0;2处填 n=1;当 n 为其他值时,为前两项

7、的和。因此3处填proc(n-1)+proc(n-2)。二、改错题(总题数:1,分数:30.00)1.下列给定程序中函数 fun 的功能是按以下递归公式求函数值。例如,当给 n 输入 3 时,函数值为 60;当给 n 输入 6 时,函数值为 480。请修改程序中的错误,使它能得到正确结果。注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。试题程序:#includestdio.h/*found*fun(int n);int j;/*found*if(n=1)j=15;elsej=fun(n=1) *2;return(j);void main()int n;printf(“E

8、nter n: “);scanf(“%d“, printf(“The result: %d/n/n“, fun(n);(分数:30.00)填空项 1:_ (正确答案:(1)错误:fun(int n); 正确:fun(int n)(2)错误:if(n=1) 正确:if(n=1))解析:解析 根据 C 语言的语法规则,函数定义之后是不加分号的。由整个程序看,函数 fun 是函数定义。因此“fun(int n);”应改为“fun(int n);”表达式 n=1 表示的是将 1 赋给变量 n显然是不对的。这里应该判断变量 n 是否等于 1。因此 if(n=1)应改为 if(n=1)。三、编程题(总题数

9、1,分数:40.00)2.编写函数 proc(),函数的功能是:根据以下公式计算 s,计算结果作为函数值返回,m 通过形参传入。S=1+1/(1+2)+1/(1+2+3)+1/(1+2+3+m)例如,若 n 的值为 11 时,函数的值为 1.833333。注意:部分源程序已给出。请勿改动主函数 main 和其他函数中的任何内容。试题程序:#includestdlib.h#includeconio.h#includestdio.h#includestring.hfloat proc(int m)void main()int m;float s;system (“CLS“);printf(“/n

10、Please enter M: “);scanf(“%d“, s=proc(m);printf(“The result is: %f/n“, s);(分数:40.00)_正确答案:(float proc(int m)int i, s1=0; /s1 表示的为分母float s=0.0;for(i=1; i=m; i+)s1=s1+i;s=s+1.0/s1; /s 是放其分数的和return s; /把最后得到的和 s 返回到主函数中)解析:解析 首先定义两个变量 s1 和 s,分别用来存放计算中所用到的分母和所有分数的和。由公式可知,分母从 1 开始,每次增加 i,直至 i=m。所有分数的和放在变量 s 中,放回到主函数中。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 13893-2003 Resilient laminate and textile floor coverings - Measurement of dynamic coefficient of friction on dry floor surfaces German version EN 13893 2002《弹性、叠层和织物性地板覆盖物 .pdf DIN EN 13893-2003 Resilient laminate and textile floor coverings - Measurement of dynamic coefficient of friction on dry floor surfaces German version EN 13893 2002《弹性、叠层和织物性地板覆盖物 .pdf
  • DIN EN 13894-1-2004 Products and systems for the protection and repair of concrete structures - Test methods - Determination of fatigue under dynamic loading - Part 1 During cure G.pdf DIN EN 13894-1-2004 Products and systems for the protection and repair of concrete structures - Test methods - Determination of fatigue under dynamic loading - Part 1 During cure G.pdf
  • DIN EN 13894-2-2003 Products and systems for the protection and repair of concrete structures - Test methods Determination of fatigue under dynamic loading - Part 2 After hardening.pdf DIN EN 13894-2-2003 Products and systems for the protection and repair of concrete structures - Test methods Determination of fatigue under dynamic loading - Part 2 After hardening.pdf
  • DIN EN 13895-2003 Textiles - Monofilaments - Determination of tensile properties German version EN 13895 2003《织物 单丝 抗拉特性的测定》.pdf DIN EN 13895-2003 Textiles - Monofilaments - Determination of tensile properties German version EN 13895 2003《织物 单丝 抗拉特性的测定》.pdf
  • DIN EN 13897-2005 Flexible sheets for waterproofing - Bitumen plastic and rubber sheets for roof waterproofing - Determination of watertightness after stretching at low temperature.pdf DIN EN 13897-2005 Flexible sheets for waterproofing - Bitumen plastic and rubber sheets for roof waterproofing - Determination of watertightness after stretching at low temperature.pdf
  • DIN EN 13898-2009 Machine tools - Safety - Sawing machines for cold metal (includes Amendment A1 2009) English version of DIN EN 13898 2009-09《机床 安全性 冷金属锯床(包括修改件A1-2009) 英文版本DIN EN.pdf DIN EN 13898-2009 Machine tools - Safety - Sawing machines for cold metal (includes Amendment A1 2009) English version of DIN EN 13898 2009-09《机床 安全性 冷金属锯床(包括修改件A1-2009) 英文版本DIN EN.pdf
  • DIN EN 13899-2003 Roller sports equipment - Roller skates - Safety requirements and test methods German version EN 13899 2003《滚轴运动设备 旱冰鞋 安全要求和试验方法》.pdf DIN EN 13899-2003 Roller sports equipment - Roller skates - Safety requirements and test methods German version EN 13899 2003《滚轴运动设备 旱冰鞋 安全要求和试验方法》.pdf
  • DIN EN 1390-2006 Wood preservatives - Determination of the eradicant action against Hylotrupes bajulus (Linnaeus) larvae - Laboratory method German version EN 1390 2006《木材防腐剂 家天牛幼虫.pdf DIN EN 1390-2006 Wood preservatives - Determination of the eradicant action against Hylotrupes bajulus (Linnaeus) larvae - Laboratory method German version EN 1390 2006《木材防腐剂 家天牛幼虫.pdf
  • DIN EN 13900-4-2004 Pigments and extenders - Methods of dispersion and assessment of dispersibility in plastics - Part 4 Determination of colouristic properties and ease of dispers.pdf DIN EN 13900-4-2004 Pigments and extenders - Methods of dispersion and assessment of dispersibility in plastics - Part 4 Determination of colouristic properties and ease of dispers.pdf
  • 相关搜索

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

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