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

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

1、国家二级 C语言机试(操作题)模拟试卷 436及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是: 根据形参 i的值返回某个函数的值。当调用正确时,程序输出: x1=5 000000,x2=3 000000,x1*x1+x1*x2=40 0000000 注意:部分源程序在文件 BLANKl C中。 不得增行或删行,也不得更改程序的结构! 试题程序: #include stdio h double f1 (double x) return x * x; double f2 (double x, double y) return x*y; /*found*/ 【 1】 fun (i

2、nt i, double x, double y) return 【 2】 (x) ; else /*found*/ return 【 3】 (x, y) ; main () double x1=5, x2 =3, r: r = fun (1, x1, x2); r + = fun (2, x1, x2); printf (“nxl = f, x2 = f, x1 * x1+x1 *x2 = fnn“,xl, x2, r) ; 二、程序修改题 2 下列给定程序中,函数 fun的功能是:比较两个字符串,将长的字符串的首地址作为函数值返回。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源

3、程序在文件 MODIl,C中,不要改动 main函数,不得增行或删行,也不得更改 程序的结构! 试题程序: #include conio h #include stdio h /*found*/ double fun (char* s,char *t) int s1 =0,t1 =0; char * ss, * tt; ss=s; tt = t; while ( *ss ) while ( *tt) t1+; if (t1 s1) return t; else return s; void main () char a80,b80 ; printf (“nEnter a string : “)

4、 gets (a); printf ( “ nEnter a string a一 gets (b) ; printf “nThe longer is : n 三、程序设计题 3 请编写函数 fun,其功能是:移动字符串中的内容,移动的规 则是把第 1一 m个字符,平移到字符串的最后,把第 m+1到最后的字符移到字符串的前部。 例如,字符串中原有的内容为 “ABCDEFGHI JK“, m的值为 3,移动后,字符串中的内容应该是 “DEFGHUKABC“。 注意:部分源程序在文件 PROG1 C中。 请勿改动 main函数和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。

5、 试题程序: #include stdio h #include string h #define N 80 void fun (char*w,int m) void main () FILE *wf; char a N = “ ABCDEFGHIJK“, b N = “ABCDEFGHIJK“; int m; printf (“The origina string :n“) ; puts (a) ; printf (“nnEnter m: “) ; fun (a,m) ; printf ( “ nThe string after moving :n“) ; puts (a) ; printf

6、 (“nn“) ; /*found*/ wf = fopen (“out dat“, “w“) ; fun (b,3) ; fprintf (wf,“ s“,b) ; fclose (wf) ; /*found*/ 国家二级 C语言机试(操作题)模拟试卷 436答案与解析 一、程 序填空题 1 【正确答案】 (1)double (2)f1 (3)f2 【试题解析】 填空 1:本空函数 fun的返回值,根据 return可知,不论返回的是n还是 f2,它们的返回值均为 double型的,故此空应该填写 double。 填空 2:因为函数 fun的功能是根据形参 i的值返回某个函数的值,当 i等于

7、 1时,应该返回的是 f1。 填空 3:如果不满足 if的话,应该返回的是 f2。 二、程序修改题 2 【正确答案】 (1)char*fun( char*s, char*t) (2)ss+; (3)tt+; 【试题解析】 (1)在主函数的输出语句中,函数 fun是以字符串格式输出的,所以定义函数时应为 char*fun(char *s,char *t) (2)和 (3)这里是地址加 1,而不是内容加 1,所以改为 ss+和 tt+。 三、程序设计题 3 【正确答案】 void fun( char*w,int m) int i,j; char t; for(i=1; i =m; i+)/*进行于 m次的循环左移 */ t=w0; for(j=1; wj!=0; j+) /*从第 2个字符开始以后的 每个字符都依次前移一个字符 / wj一 1=wj; wj 一 1 =t; /*将第 1个字符放到最后一个字符中 */ 【试题解析】 本题应采用 “循环左移 ”的算法,多层循环用于控制移动的字符的个数,即需进行多少次循环,内嵌循环的作用是将从第 2个字符以后的每个字符依次前移一个位置,最后将第 1个字符放到最后一个字符中。

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