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

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

1、国家二级 C语言机试(操作题)模拟试卷 455及答案与解析 一、程序填空题 1 下列给定程序中,函数 fun的功能是:计算 NN矩阵的主对角线元素和反向对角线元素之和,并作为函数值返回。要求先累加主对角线元素中的值,再累加反向对角线元素中的值。 例如,若 N=3,有下列矩阵: 1 2 3 4 5 6 7 8 9 首先累加 1、 5、 9,然后累加 3、 5、 7,函数返回值为 30。 请在程序的下画线处填入正确的内容并将下画 线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #define N 4

2、 fun(int tN, int n) int i, sum; /*found*/ 【 1】 ; for(i=0; i n ; i+) /*found*/ sum+=【 2】 ; for(i=0; i n; i+) /*found*/ sum+: tini一 【 3】 ; return sum; main() int i, j, t: N=21, 2, 13, 24, 25, 16, 47, 38, 29, 11, 32, 54, 42,21, 3, 10); printf(“nThe orifinal data: n“); for(i=0; i N; i+) for(j=0, j N; j+

3、) printf(“ 4d“, tij); printf(“n“); printf(“The result is: d“, fun(t, N); 二、程序修改题 2 下列给定程序中,函数 fun和 funx的功能是:用二分法求方程 2x3一 4x2+3x一6=0的一个根,并要求绝对误差不超过 0 001。 例如,若给 m输入一 100,给 n输入 90,则函数求得的一个根为 2 000。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得 更改程序的结构 ! 试题程序: #include stdio h #include math h double

4、 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(1abs(n一 m) 0 001) if(funx(r)jIc funx(n) 0) m=r; else n=r; r=(m+n)/2; return r; main() double m, n, root; printf(“Enter m n: n“); scanf(“ lf lf“, &m, &n); root=fun(m, n); printf(“

5、root= 6 3fn“, root); 三、程序设计题 3 规定输入的字符串中只包含字母和 *号。编写函数 fun,其功能是:除了字符串前导和尾部的 *号外,将串中其他的 *号全部删除。形参 h已指向字符串中第 个字母,形参 P指向字符串中最后一个字母。在编写函数时,不得使用 C语言提供的字符串函数。 例如,若字符串中的内容为 “*A*BC*DEF*G*”,删除后,字符串中的内容应当是 “*ABCDEFG*”。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio h #incl

6、ude conio h #include string h void fun(char*a, char*h, char*p) main() char s81, *t, *f; printf(“Enter a string: n“); gets(s); t=f=s; while(*t) t+; t一一; while(*t=*) t一一; while(*f=*) f+; fun(s, f, t); printf(“The string after deleted: n“); puts(s); 国家二级 C语言机试(操作题)模拟试卷 455答案与解析 一、程序填空题 1 【正确答案】 (1)sum

7、0 (2)tii (3)1 【试题解析】 填空 1:变量 sum用来储存 “和 ”结果,所以将其初始化为 0。 填空 2:从题目中可以了解到,主对角线元素的行和列下标是相同的 ,所以应填入tii。 填空 3:对于反向对角线元素的行和列的下标,它们的关系是相加和为 n一 1,所以应填入 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,所以循环

8、条件应为 fabs(n一 m) 0 001。 三、程序设计题 3 【正确答案】 void fun (char*a,char *h,char *p) int i=0; char*q=a; /*将前导 *号保存到 a中 */ while (q h) ai=*q; q+; i+; /*继续遍历数组 */ while (q p) if( *q!=*) /*如果不是 *保存到 a中 */ ai=*q; i+; q+; /*将末尾 *号保存到 a中 */ while (*q) 【试题解析】 本题的重点是要选择好判断条件,首先是需要判断前导 *号的结束,然后判断 是否指向最后一个字母,最后补充尾部 *号,只要思路对了即可正确解答。

展开阅读全文
相关资源
猜你喜欢
  • 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