【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷307及答案解析.doc

上传人:arrownail386 文档编号:1332121 上传时间:2019-10-17 格式:DOC 页数:2 大小:31.50KB
下载 相关 举报
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷307及答案解析.doc_第1页
第1页 / 共2页
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷307及答案解析.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 307及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是:把形参 s所指字符串中最右边的 n个字符复制到形参 t所指字符数组中,形成一个新串。若 s所指字符串的长度小于 n,则将整个字符串复制到形参 t所指字符数组中。 例如,形参 s所指的字符串为:abedefgh,n 的值为 5,程序执行后 t所指字符数组中的字符串应为:defgh。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1C 中。 不得增行或删行,也不得

2、更改程序的结构! 试题程序: #includestdioh #includestringh #defiFte N 80 void fun(char*s,int n,char,*t) intz len,i,j=0; len=strlen(s); *found* if(n=len)strcpy( 【1】 ); else *found* for(i=lenn;i=len1;i+) tj+= 【2】 ; *found* tj= 【3】 ; main() char sN,tN;int n; printf(“Enter a string:“); gets(s); printf(“Enter n:“); s

3、canf(“d“,n); fun(s,n,t);printf(“The string t:“); puts(t); (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中函数 fun的功能是:把从主函数中输入的 3个数,最大的数放在 a中,中间的数放在 b中,最小的数放在 c中。例如,若输入的数为:55 12 34,输出的结果应当是:a=550,b:340,c=120。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includestdiohvoid fun(float*a,float*b,f

4、loat*c)*found* float*k; if(*a*b) k=*a; *a=*b; *b=k; *found* if(*a*c) k=*c; *c=*a; *a=k; if(*b*c) k=*b; *b=*c; *c=k; main() float a,b,c; printf(“Input a b c:“); scanf(“fff“,a,b,c); printf(“a=41f,b=41f,c=41fnn”,a,b,c);fun(a,b,c); printf(“a=41f,b=41f,c=41fnn“,a,b,c);(分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.编写

5、函数 fun,其功能是:求 Fibonacci数列中大于 t的最小的数,结果由函数返回。Fibonacci 数列F(n)的定义为:F(0)=0,F(1)=1F(n)=F(n 一 1)+F(n一 2)例如,当 t=1000时,函数值为 1597。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序:#includeconioh#includemathh#includestdiohint fun(int t)main() int n; n=1000; printf(“n=d,f=dn“,n,fun(n);(分数:2.00

6、)_国家二级 C语言机试(操作题)模拟试卷 307答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是:把形参 s所指字符串中最右边的 n个字符复制到形参 t所指字符数组中,形成一个新串。若 s所指字符串的长度小于 n,则将整个字符串复制到形参 t所指字符数组中。 例如,形参 s所指的字符串为:abedefgh,n 的值为 5,程序执行后 t所指字符数组中的字符串应为:defgh。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1C 中。 不得增行或删行,也不

7、得更改程序的结构! 试题程序: #includestdioh #includestringh #defiFte N 80 void fun(char*s,int n,char,*t) intz len,i,j=0; len=strlen(s); *found* if(n=len)strcpy( 【1】 ); else *found* for(i=lenn;i=len1;i+) tj+= 【2】 ; *found* tj= 【3】 ; main() char sN,tN;int n; printf(“Enter a string:“); gets(s); printf(“Enter n:“);

8、scanf(“d“,n); fun(s,n,t);printf(“The string t:“); puts(t); (分数:2.00)_正确答案:(正确答案:(1)t,s (2)si (3)0 或0)解析:解析:填空 1:当给定的长度 n大于该字符串 s的长度,那么把该字符串直接拷贝到 t就可以了,所以应填 t,s。 填空 2:使用 for循环语句,把最右边 n个字符依次添加到 t中,所以应填 si。 填空 3:字符串操作结束,需要给 t加一个字符串结束符,所以应填 0或0。二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中函数 fun的功能是:把从主函数中输入的 3个数,最大的

9、数放在 a中,中间的数放在 b中,最小的数放在 c中。例如,若输入的数为:55 12 34,输出的结果应当是:a=550,b:340,c=120。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includestdiohvoid fun(float*a,float*b,float*c)*found* float*k; if(*a*b) k=*a; *a=*b; *b=k; *found* if(*a*c) k=*c; *c=*a; *a=k; if(*b*c) k=*b; *b=*c; *c=k; main() floa

10、t a,b,c; printf(“Input a b c:“); scanf(“fff“,a,b,c); printf(“a=41f,b=41f,c=41fnn”,a,b,c);fun(a,b,c); printf(“a=41f,b=41f,c=41fnn“,a,b,c);(分数:2.00)_正确答案:(正确答案:(1)noat k; (2)if(*a*c)解析:解析:(1)观察程序中的 k,在赋值语句中,k 是以变量的形式进行赋值而非指针,所以将 k定义为指针是错误的。 (2)此处 if语句是为了将小于*c 的值放入*c 中,所以改为 if(*a*c)。三、程序设计题(总题数:1,分数:2.

11、00)3.编写函数 fun,其功能是:求 Fibonacci数列中大于 t的最小的数,结果由函数返回。Fibonacci 数列F(n)的定义为:F(0)=0,F(1)=1F(n)=F(n 一 1)+F(n一 2)例如,当 t=1000时,函数值为 1597。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序:#includeconioh#includemathh#includestdiohint fun(int t)main() int n; n=1000; printf(“n=d,f=dn“,n,fun(n);(分数:2.00)_正确答案:(正确答案:int fun(int t) int f0=0,f1=1,f; do *根据 Fibonacci数列的定义求数值* f=f0+f1; f0=f1;f1=f; while(ft);*如果求的数值小于 t则继续* return f; )解析:解析:根据所给数列定义不难发现,该数列最终的结果是由两个数列之和组成,所以可以在循环内部始终把 f看成是前两项之和,而 f0始终代表第 n一 2项,f1 代表第 n一 1项。退出循环时得到的数f,就是大于指定数的最小的数。

展开阅读全文
相关资源
猜你喜欢
  • BS EN 13126-7-2007 Building hardware - Requirements and test methods for windows and door height windows - Part 7 Finger catches《建筑五金 窗和门高窗的要求和试验方法 指形拉手》.pdf BS EN 13126-7-2007 Building hardware - Requirements and test methods for windows and door height windows - Part 7 Finger catches《建筑五金 窗和门高窗的要求和试验方法 指形拉手》.pdf
  • BS EN 13126-9-2013 Building hardware Requirements and test methods for windows and door height windows Hardware for horizontal and vertical pivot windows《建筑五金件 窗户和与门同高的窗户的试验方法和要求 水.pdf BS EN 13126-9-2013 Building hardware Requirements and test methods for windows and door height windows Hardware for horizontal and vertical pivot windows《建筑五金件 窗户和与门同高的窗户的试验方法和要求 水.pdf
  • BS EN 13129-2016 Railway applications Air conditioning for main line rolling stock Comfort parameters and type tests《轨道交通 主干线铁路车辆用空调 舒适度参数与型式试验》.pdf BS EN 13129-2016 Railway applications Air conditioning for main line rolling stock Comfort parameters and type tests《轨道交通 主干线铁路车辆用空调 舒适度参数与型式试验》.pdf
  • BS EN 13130-1-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Guide to test methods for the specific migration of substances frd.pdf BS EN 13130-1-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Guide to test methods for the specific migration of substances frd.pdf
  • BS EN 13130-2-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Determination of terephthalic acid in food simulants《接触食品的材料和物品 有.pdf BS EN 13130-2-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Determination of terephthalic acid in food simulants《接触食品的材料和物品 有.pdf
  • BS EN 13130-3-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Determination of acrylonitrile in food and food simulants《接触食品的材料.pdf BS EN 13130-3-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Determination of acrylonitrile in food and food simulants《接触食品的材料.pdf
  • BS EN 13130-4-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Determination of 1 3-butadiene in plastics《接触食品的材料和物品 有限制的塑料物质 塑料.pdf BS EN 13130-4-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Determination of 1 3-butadiene in plastics《接触食品的材料和物品 有限制的塑料物质 塑料.pdf
  • BS EN 13130-5-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Determination of vinylidene chloride in food simulants《接触食品的材料和物品.pdf BS EN 13130-5-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Determination of vinylidene chloride in food simulants《接触食品的材料和物品.pdf
  • BS EN 13130-6-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Determination of vinylidene chloride in plastics《与食品有关的材料和物品 有限制的.pdf BS EN 13130-6-2004 Materials and articles in contact with foodstuffs - Plastics substances subject to limitation - Determination of vinylidene chloride in plastics《与食品有关的材料和物品 有限制的.pdf
  • 相关搜索

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

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