【计算机类职业资格】全国计算机二级C语言上机试题55+2015年及答案解析.doc

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

1、全国计算机二级 C语言上机试题 55+2015年及答案解析(总分:30.00,做题时间:90 分钟)1.给定程序中,函数 fun的功能是:判断形参 s所指字符串是否是“回文“(Palindrome),若是,函数返回值为 1;不是,函数返回值为 0。“回文“是正读和反读都一样的字符串(不区分大小写字母)。 例如,LEVEL和 Level是“回文“,而 LEVLEV不是“回文“。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include #

2、include int fun(char *s) char *lp,*rp; /*found*/ lp= _1_ ; rp=s+strlen(s)-1; while(toupper(*lp)=toupper(*rp) rp _2_ ; /*found*/ if(lp else return 1; main() char s81; printf(“Enter a string: “); scanf(“%s“,s); if(fun(s) printf(“/n/“%s/“ is a Palindrome./n/n“,s); else printf(“/n/“%s/“ isnt a Palindrom

3、e./n/n“,s); (分数:10.00)_2.给定程序 MODI1.C中 fun函数的功能是:求出以下分数序列的前 n项之和。 2 3 5 8 13 21 , , , , , , 1 2 3 5 8 13 和值通过函数值返回 main函数。 例如,若 n = 5,则应输出: 8.391667。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #include /*found*/ fun (int n ) int a = 2, b = 1, c, k ; double s=0.0 ; for ( k = 1;

4、k = n; k+ ) s = s + 1.0 * a / b ; /*found*/ c = a; a += b; b += c; return(s) ; main( ) int n = 5 ; printf( “/nThe value of function is: %lf/n“, fun ( n ) ) ; (分数:10.00)_3.请编写函数 fun,函数的功能是:将大于形参 m且紧靠 m的 k个素数存入 xx所指的数组中。例如,若输入 17, 5,则应输出:19, 23, 29, 31, 37。函数 fun中给出的语句仅供参考。 注意: 部分源程序在文件 PROG1.C文件中。 请勿

5、改动主函数 main和其它函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 给定源程序: #include void fun(int m, int k, int xx) /* 以下代码仅供参考 */ int i, j=1, t=m+1; while(j=k) /* 以下完成判断素数,并存放到数组 xx中 */ main() int m, n, zz1000 ; printf( “/nPlease enter two integers:“) ; scanf(“%d%d“, fun( m, n, zz) ; for( m = 0 ; m n ; m+ ) printf(“%d “

6、 zzm) ; printf(“/n“) ; NONO( ) ; (分数:10.00)_全国计算机二级 C语言上机试题 55+2015年答案解析(总分:30.00,做题时间:90 分钟)1.给定程序中,函数 fun的功能是:判断形参 s所指字符串是否是“回文“(Palindrome),若是,函数返回值为 1;不是,函数返回值为 0。“回文“是正读和反读都一样的字符串(不区分大小写字母)。 例如,LEVEL和 Level是“回文“,而 LEVLEV不是“回文“。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C中。不得

7、增行或删行,也不得更改程序的结构! 给定源程序: #include #include #include int fun(char *s) char *lp,*rp; /*found*/ lp= _1_ ; rp=s+strlen(s)-1; while(toupper(*lp)=toupper(*rp) rp _2_ ; /*found*/ if(lp else return 1; main() char s81; printf(“Enter a string: “); scanf(“%s“,s); if(fun(s) printf(“/n/“%s/“ is a Palindrome./n/n

8、s); else printf(“/n/“%s/“ isnt a Palindrome./n/n“,s); (分数:10.00)_正确答案:(第一处:根据函数体 fun中,对变量 lp的使用可知,lp 应指向形参 s,所以应填:s。 第二处:rp 是指向字符串的尾指针,当每做一次循环 rp指向就要指向前一个字符,所以应填:-。 第三处:当 lp和 rp相等时,则表示字符串是回文并返回 1,否则就返回 0,所以应填:return0。)解析:2.给定程序 MODI1.C中 fun函数的功能是:求出以下分数序列的前 n项之和。 2 3 5 8 13 21 , , , , , , 1 2 3 5

9、8 13 和值通过函数值返回 main函数。 例如,若 n = 5,则应输出: 8.391667。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #include /*found*/ fun (int n ) int a = 2, b = 1, c, k ; double s=0.0 ; for ( k = 1; k = n; k+ ) s = s + 1.0 * a / b ; /*found*/ c = a; a += b; b += c; return(s) ; main( ) int n = 5 ; p

10、rintf( “/nThe value of function is: %lf/n“, fun ( n ) ) ; (分数:10.00)_正确答案:(第一处:由于计算的实型值要通过函数返回,所以必须定义函数的返回类型,只要 int或void可以省略,其他都要定义类型。由于返回是实型值,所以应在数名前加上 double或 float等定义。 第二处:根据公式可知,在 for循环内 b的值应是 c。)解析:3.请编写函数 fun,函数的功能是:将大于形参 m且紧靠 m的 k个素数存入 xx所指的数组中。例如,若输入 17, 5,则应输出:19, 23, 29, 31, 37。函数 fun中给出的语

11、句仅供参考。 注意: 部分源程序在文件 PROG1.C文件中。 请勿改动主函数 main和其它函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 给定源程序: #include void fun(int m, int k, int xx) /* 以下代码仅供参考 */ int i, j=1, t=m+1; while(j=k) /* 以下完成判断素数,并存放到数组 xx中 */ main() int m, n, zz1000 ; printf( “/nPlease enter two integers:“) ; scanf(“%d%d“, fun( m, n, zz) ; for( m = 0 ; m n ; m+ ) printf(“%d “, zzm) ; printf(“/n“) ; NONO( ) ; (分数:10.00)_正确答案:(void fun(int m, int k, int xx) /* 以下代码仅供参考 */ int i, j=1, t=m+1; while(j=k) /* 以下完成判断素数,并存放到数组 xx中 */ for(i = 2 ; i t; i+) if(t % i=0) break; if(i=t) xxj-1 = i; j+; t+; )解析:

展开阅读全文
相关资源
猜你喜欢
  • ISO 8032-1997 Rubber and plastics hose assemblies - Flexing combined with hydraulic impulse test (half-omega test)《橡胶和塑料软管组件 液压脉冲弯曲试验(半Ω 型试验)》.pdf ISO 8032-1997 Rubber and plastics hose assemblies - Flexing combined with hydraulic impulse test (half-omega test)《橡胶和塑料软管组件 液压脉冲弯曲试验(半Ω 型试验)》.pdf
  • ISO 8035-1991 Commercial road vehicles and buses over 3 5 t front towing attachments《超过3 5t的商用车辆和公共汽车 前牵引装置》.pdf ISO 8035-1991 Commercial road vehicles and buses over 3 5 t front towing attachments《超过3 5t的商用车辆和公共汽车 前牵引装置》.pdf
  • ISO 80369-7-2016 Small-bore connectors for liquids and gases in healthcare applications - Part 7 Connectors for intravascular or hypodermic applications《卫生保健设施中.pdf ISO 80369-7-2016 Small-bore connectors for liquids and gases in healthcare applications - Part 7 Connectors for intravascular or hypodermic applications《卫生保健设施中.pdf
  • ISO 8037-1-1986 Optics and optical instruments Microscopes Slides Part 1 Dimensions optical properties and marking《光学和光学仪器 显微镜 载玻片 第1部分 尺寸、光学性能和标志》.pdf ISO 8037-1-1986 Optics and optical instruments Microscopes Slides Part 1 Dimensions optical properties and marking《光学和光学仪器 显微镜 载玻片 第1部分 尺寸、光学性能和标志》.pdf
  • ISO 8037-2 CORR 1-2002 Optics and optical instruments - Microscopes Slides - Part 2 Quality of material standards of finish and mode of packaging Technical Corr.pdf ISO 8037-2 CORR 1-2002 Optics and optical instruments - Microscopes Slides - Part 2 Quality of material standards of finish and mode of packaging Technical Corr.pdf
  • ISO 8037-2-1997 Optics and optical instruments - Microscopes - Slides - Part 2 Quality of material standards of finish and mode of packaging《光学和光学仪器 显微镜 载玻片 第2部.pdf ISO 8037-2-1997 Optics and optical instruments - Microscopes - Slides - Part 2 Quality of material standards of finish and mode of packaging《光学和光学仪器 显微镜 载玻片 第2部.pdf
  • ISO 8039-2014 Microscopes - Values tolerances and symbols for magnification《显微镜 放大率的值 容差和符号》.pdf ISO 8039-2014 Microscopes - Values tolerances and symbols for magnification《显微镜 放大率的值 容差和符号》.pdf
  • ISO 804-1976 Aluminium oxide primarily used for the production of aluminium Preparation of solution for analysis Method by alkaline fusion《主要用于铝生产的氧化铝 分析用溶液的制备 .pdf ISO 804-1976 Aluminium oxide primarily used for the production of aluminium Preparation of solution for analysis Method by alkaline fusion《主要用于铝生产的氧化铝 分析用溶液的制备 .pdf
  • ISO 80416-2-2001 Basic principles for graphical symbols for use on equipment - Part 2 Form and use of arrows《设备用图形符号基本原则 第2部分:表格和箭头的使用》.pdf ISO 80416-2-2001 Basic principles for graphical symbols for use on equipment - Part 2 Form and use of arrows《设备用图形符号基本原则 第2部分:表格和箭头的使用》.pdf
  • 相关搜索
    资源标签

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

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