[计算机类试卷]国家二级C语言机试(操作题)模拟试卷288及答案与解析.doc

上传人:王申宇 文档编号:498221 上传时间:2018-11-28 格式:DOC 页数:3 大小:31KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷288及答案与解析.doc_第1页
第1页 / 共3页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷288及答案与解析.doc_第2页
第2页 / 共3页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷288及答案与解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 288及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是:计算下式前 n项的和,并作为函数值返回。例如,当形参 n的值为 10时,函数返回一 0 204491。请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。注意:源程序给出如下。不得增行或删行,也不得更改程序的结构 !试题程序: #inclucle stdio h double fun(int n) int i, k; double s, t; s=0;*found* k=【 1】; for(i=1; i =n; i+)*found* t=【 2】; s=s+k*(

2、2*i一 1)*(2*i+1) (t*t);*found* k=k*【 3】; return s; main() int n= 1; while(n 0) printf(“Please input(n 0): “); scanf(“ d, &n); printf(“ nThe result is: f n“, fun(n); 二 、程序修改题 2 下列给定程序中,函数 fun和 funx的功能是:用二分法求方程 2x3一 4x2+3x一6=0的一个根,并要求绝对误差不超过 0 001。 例如,若给 m输入一 100,给 n输入 90,则函数求得的一个根为 2 000。 请改正程序中的错误,使它

3、能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #include math h double funx(double x) return(2*x*x*x 4*x*x+3*x 6); double fun(double m, double n) *found* int r; r=(m+n) 2; *found* while(fabs(n m) 0 001) if(funx(r)*funx(n) 0) m=r; else n=r; r=(m+n) 2 ; return r; main() double m,

4、n, root; printf(“Enter m n: n“); scanf(“ lflf“, &m, n); root=fun(m, n); printf(“root= 6 3f n“, root); 三、程序设计题 3 函数 fun的功能是:将 a、 b两个两位正整数合并成一个新的整数放在 c中。合并的方式是:将 a中的十位和个位数依次放在变量 c的百位和个位上, b中的十位和个位数依次放在变量 c的千位和十位上。 例如,当 a=45, b=12,调用该函数后 c=1425。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的

5、若干语句。 试题程序: #include conio h #include stdio h void fun(int a, int b, long*c) main() int a, b; long c; printf(“Input a, b: “); scanf(“ d d“, a, b); fun(a, b, c); printf(“The result is: id n“, c), 国家二级 C语言机试(操作题)模拟试卷 288答案与解析 一、程序填空题 1 【正确答案】 (1)1 (2)2*i (3)( 1) 【试题解析】 填空 1:由 fun函数整体结构可以看出 k的作用是赋值,并累加

6、各项前边的正负号,由于第一项是正的,因此赋给 k的值为 1。 填空 2:此空下一行的表达式 k*(2*i一 1)*(2*i+1) (t*t)累加的通项, k为正负号,由题目中的公式可知 t=2*i。 填空 3:由于通项前边的正负号每次都要发生变化,因此 k=k*(一 1)。 二、程序修改题 2 【正确答案】 (1)double r; (2)while(fabs(n m) 0 001) 【试题解析】 (1)程序中会发现 r=(m+n) 2,而 m和 n都是 double型的,并且根据题意可知,变量 r需要定义为 double型。 (2)绝对误差不超过 0 001,所以循环条件应为 fabs(n

7、m) 0 001。 三、程序设计题 3 【正确答案】 void fun(int a, int b, long*c) *b 1 0获取 b的个位, a 10获取 a的十位, a 10获取 a的个位, b 10获取 b的 十位 * *c=a 10+(b 10)*10+(a 10)*100+(b 10)*1000; 【试题解析】 本题的主要问题是如何取出 a和 b的个位数和十位数,取出后如何表示成 c中相应的位数。由于 a和 b都是只有两位的整数,所以分别对它们除 10可得到它们的十位数,分别用 10对它们求余可得到它们的个位数。得到后对应乘以 1000、 100、 10、 1,就可得到 c的千位数、百位数、十位数和个位数。注意使用 c时要进行指针运算。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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