【计算机类职业资格】二级C语言-294及答案解析.doc

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

1、二级 C 语言-294 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:判断形参 s 所指字符串是否是“回文”(Palindrome),若是,函数返回值为 1;不是,函数返回值为 0。“回文”是正读和反读都一样的字符串(不区分大小写字母)。 例如,LEVEL 和 Level 是“回文”,而 LEVLEV 不是“回文”。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 不得增行或删行,也不得更改程序的结构! 给定源程序: #includestdio.h #includestring

2、h #includectype.h int fun(char *s) char *lp, *rp; /*found*/ lp= 1; rp=s+strlen(s)-1; while(toupper(*lp)=toupper(*rp) rp 2; /*found*/ if(lprp) 3; else relurn 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“isn“t a

3、Palindrome./n/n“. s); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.给定程序中 fun 函数的功能是:求出以下分数序列的前 n 项之和。和值通过函数值返回 main 函数。 (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写函数 fun,函数的功能是:将大于形参 m 且紧靠 m 的 k 个素数存入 xx 所指的数组中。函数 prime判断一个数是否为素数,是返回 1,否则返回 0。例如,若输入 17,5,则应输出:19,23,29,31,37。函数 fun 中给出的语句仅供参考。 请勿改动主函数 main 和其它函数中的任

4、何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #includestdio.h int prime(int n) int m; for(m=2; mn; m+) if(n%m=0) return 0; return 1; void fun(int m, int k, int xx) /*以下代码仅供参考*/ int j=0, t=m+1; while(jk) /*按题目要求完成以下代码*/ main() int m, n, zz1000; printf(“/Please enter two integers:“); scanf(“%d%d“, fun(m, n, zz

5、); for(m=0; mn; m+) fprintf(“%d“, zzm); printf(“/n“); (分数:40.00)_二级 C 语言-294 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:判断形参 s 所指字符串是否是“回文”(Palindrome),若是,函数返回值为 1;不是,函数返回值为 0。“回文”是正读和反读都一样的字符串(不区分大小写字母)。 例如,LEVEL 和 Level 是“回文”,而 LEVLEV 不是“回文”。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出

6、正确的结果。 不得增行或删行,也不得更改程序的结构! 给定源程序: #includestdio.h #includestring.h #includectype.h int fun(char *s) char *lp, *rp; /*found*/ lp= 1; rp=s+strlen(s)-1; while(toupper(*lp)=toupper(*rp) rp 2; /*found*/ if(lprp) 3; else relurn 1; main() char s81; printf(“Enter a string:“); scanf(“%s“, s); if(fun(s) print

7、f(“/n“%s“ is a Palindrome./n/n“, s); else printf(“/n“%s“isn“t a Palindrome./n/n“. s); (分数:30.00)解析:(1)s (2)- (3)return 0 解析 填空 1:根据函数体 fun 中,对变量 lp 和 rp 的使用可知,lp 应指向形参 s 的起始地址,rp 指向 s 的结尾地址,所以应填 s。 填空 2:rp 是指向字符串的尾指针,当每做一次循环 rp 向前移动一个位置,所以应填:-。 填空 3:当 lp 和 rp 相等时,表示字符串是回文并返回 1,否则就返回 0,所以应填 return 0。

8、二、程序改错题(总题数:1,分数:30.00)2.给定程序中 fun 函数的功能是:求出以下分数序列的前 n 项之和。和值通过函数值返回 main 函数。 (分数:30.00)解析:(1)double fun(int n) (2)c=a; a+=b; b=c; 解析 (1)由于返回值是 double 型的,所以函数要定义为 double 型。 (2)将 c 赋值为 b 即 b=c,使之成为下一项的分母。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 fun,函数的功能是:将大于形参 m 且紧靠 m 的 k 个素数存入 xx 所指的数组中。函数 prime判断一个数是否为素数,是返

9、回 1,否则返回 0。例如,若输入 17,5,则应输出:19,23,29,31,37。函数 fun 中给出的语句仅供参考。 请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #includestdio.h int prime(int n) int m; for(m=2; mn; m+) if(n%m=0) return 0; return 1; void fun(int m, int k, int xx) /*以下代码仅供参考*/ int j=0, t=m+1; while(jk) /*按题目要求完成以下代码*/ main()

10、int m, n, zz1000; printf(“/Please enter two integers:“); scanf(“%d%d“, fun(m, n, zz); for(m=0; mn; m+) fprintf(“%d“, zzm); printf(“/n“); (分数:40.00)_正确答案:()解析:void fun(int m, int k, int xx) int i, j, n; for(i=m+1, n=0; nk; i+) for(j=2; ji; j+) if(i%j=0)break; if(j=i) xxn+=i; 解析 本题主要考查素数的判定方法,如果一个数不能被除了 1 和其自身以外的数整除,则这个数为素数。本程序使用循环语句控制需要判断的数,在循环体中判断该数是否为素数,若是则存入数组 xx 中。

展开阅读全文
相关资源
猜你喜欢
  • ASD-STAN PREN 3639-1994 Aerospace Series Heat Resisting Alloy FE-PA2601 Softened and Cold Worked Wire for Forged Fasteners D is Less Than or Equal to 15 mm 900 MPa is Less Than or .pdf ASD-STAN PREN 3639-1994 Aerospace Series Heat Resisting Alloy FE-PA2601 Softened and Cold Worked Wire for Forged Fasteners D is Less Than or Equal to 15 mm 900 MPa is Less Than or .pdf
  • ASD-STAN PREN 3640-1992 Aerospace Series Test Methods Heat Resisting Alloys Atomized Powder Procedure for the Inspection of Loose Powder Cleanness by Water Elutriation (Edition P 1.pdf ASD-STAN PREN 3640-1992 Aerospace Series Test Methods Heat Resisting Alloys Atomized Powder Procedure for the Inspection of Loose Powder Cleanness by Water Elutriation (Edition P 1.pdf
  • ASD-STAN PREN 3641-1992 Aerospace Series Test Methods Heat Resisting Alloys Compacted Material Procedure for Quantitative Determination of Thermally Induced Porosity (T I P ) (Edit.pdf ASD-STAN PREN 3641-1992 Aerospace Series Test Methods Heat Resisting Alloys Compacted Material Procedure for Quantitative Determination of Thermally Induced Porosity (T I P ) (Edit.pdf
  • ASD-STAN PREN 3642-1990 Aerospace Series Rivets Solid 100 Degrees Normal Countersunk Head with Dome in Titanium TI-P02 Anodized (Issue P 1)《航空航天系列 公制系列经阳极化处理的钛TI-P02制100°普通圆顶沉头实心铆.pdf ASD-STAN PREN 3642-1990 Aerospace Series Rivets Solid 100 Degrees Normal Countersunk Head with Dome in Titanium TI-P02 Anodized (Issue P 1)《航空航天系列 公制系列经阳极化处理的钛TI-P02制100°普通圆顶沉头实心铆.pdf
  • ASD-STAN PREN 3643-1990 Aerospace Series Rivets Solid 100 Degrees Normal Countersunk Head in Titanium TI-P02 Anodized (Issue P 1)《航空航天系列 公制系列经阳极化处理的钛TI-P02制100°普通沉头实心铆钉 第P1版》.pdf ASD-STAN PREN 3643-1990 Aerospace Series Rivets Solid 100 Degrees Normal Countersunk Head in Titanium TI-P02 Anodized (Issue P 1)《航空航天系列 公制系列经阳极化处理的钛TI-P02制100°普通沉头实心铆钉 第P1版》.pdf
  • ASD-STAN PREN 3644-1990 Aerospace Series Rivets Solid Universal Head in Titanium TI P02 Anodized (Issue P 1)《航空航天系列 公制系列经阳极化处理的钛TI-P02制100°通用头实心铆钉 第P1版》.pdf ASD-STAN PREN 3644-1990 Aerospace Series Rivets Solid Universal Head in Titanium TI P02 Anodized (Issue P 1)《航空航天系列 公制系列经阳极化处理的钛TI-P02制100°通用头实心铆钉 第P1版》.pdf
  • ASD-STAN PREN 3645-001-2014 Aerospace series Connectors electrical circular scoop-proof triple start threaded coupling operating temperature 175 or 200 continuous Part 001 Technica.pdf ASD-STAN PREN 3645-001-2014 Aerospace series Connectors electrical circular scoop-proof triple start threaded coupling operating temperature 175 or 200 continuous Part 001 Technica.pdf
  • ASD-STAN PREN 3645-002-2013 Aerospace series Connectors electrical circular scoop-proof triple start threaded coupling operating temperature 175 or 200 continuous Part 002 Specific.pdf ASD-STAN PREN 3645-002-2013 Aerospace series Connectors electrical circular scoop-proof triple start threaded coupling operating temperature 175 or 200 continuous Part 002 Specific.pdf
  • ASD-STAN PREN 3645-003-2014 Aerospace series Connectors electrical circular scoop-proof triple start threaded coupling operating temperature 175 or 200 continuous Part 003 Receptac.pdf ASD-STAN PREN 3645-003-2014 Aerospace series Connectors electrical circular scoop-proof triple start threaded coupling operating temperature 175 or 200 continuous Part 003 Receptac.pdf
  • 相关搜索

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

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