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

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

1、二级 C 语言机试 89 及答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充函数 fun(),该函数的功能是:把 ASCII 码为奇数的字符从字符串 str 中删除,结果仍然保存在字符串 str 中。字符串 str 从键盘输入,其长度作为参数传入函数 fun()。 例如,输入“abcdef”,输出“bdf”。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include stdio.h #define N 80 void fun(

2、char s,int n) int i, j; j=0; for(i=0;U 【1】 /U;i+) if(U 【2】 /U) s j+-s i; U 【3】 /U; main ( ) int i=0, strlen=0; char str N; clrscr (); printf (“/nInput a string: /n“); gets (str); while (str i !=/0) strlen+; i+; fun(str, strlen); printf(“/n* display string */n“); puts (str); (分数:30.00)填空项 1:_二、B改错题/B

3、总题数:1,分数:30.00)2.下列给定的程序中,函数 hn()的功能是:为一个偶数寻找两个素数,这两个素数之和等于该偶数,并将这两个素数通过形参指针传回主函数。 请改正函数 fun()中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include stdio.h #include math.h void fun(int a, int *b, int *c) int i,j,d,y; for (i=3;i=a/2;i=i+2) /*found*/ y=0; for (j=2;j=sqrt(double)i);j+) i

4、f (i%j=0) y=0; if (y=1) /*found*/ d=i-a; for (j-2;j=sqrt(double)d); j+) if (d%j=0) y=0; if (y=-1) *b=i; *c=d; main () int a,b,c; do printf(“/nInput a: “); scanf (“%d“, while (a%2); fun (a, printf (“/n/n%d=%d+%d/n“, a,b,c); (分数:30.00)填空项 1:_三、B编程题/B(总题数:1,分数:40.00)3.请编写一个函数 void fun(char*ss),其功能是:将字符

5、串 ss 中所有下标为偶数位置上的字母转化为大写(若该位置上不是字母,则不转换)。 例如,若输入 abc4Efg,则应输出 AbC4EfG。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #includeconio. h #includestdio. h void fun ( char *ss) main ( ) char tt51; clrscr (); printf(“Please enter an character string within 50 characters:/n“); gets

6、 (tt); printf (“/n/nAfter changing, the string/n %s“, tt); fun (tt); printf(“/nbecomes/n /%s“,tt); (分数:40.00)_二级 C 语言机试 89 答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充函数 fun(),该函数的功能是:把 ASCII 码为奇数的字符从字符串 str 中删除,结果仍然保存在字符串 str 中。字符串 str 从键盘输入,其长度作为参数传入函数 fun()。 例如,输入“abcdef”,输出“bdf”。 注意:部

7、分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include stdio.h #define N 80 void fun(char s,int n) int i, j; j=0; for(i=0;U 【1】 /U;i+) if(U 【2】 /U) s j+-s i; U 【3】 /U; main ( ) int i=0, strlen=0; char str N; clrscr (); printf (“/nInput a string: /n“); gets (str); while (str i

8、 !=/0) strlen+; i+; fun(str, strlen); printf(“/n* display string */n“); puts (str); (分数:30.00)填空项 1:_ (正确答案:1 in 2 si%2=0 3 sj= /0)解析:解析 填空1:变量 n 为字符串的长度,所以字符数组的下标的取值范甲是从 0 到 n-1。填空 2:如果当前字符的 ASCII 码对 2 取余等于 0,就说明这个字符的 ASCII 码为偶数,故不能删除,而是将它存于字符串 s 中。填空 3:通过保留 ASCII 码为偶数的字符的力法,来实现删除 ASCII 码为奇数的字符的目的。

9、处理结束后,还要在字符串 s 的最后加上结束标记符/0。二、B改错题/B(总题数:1,分数:30.00)2.下列给定的程序中,函数 hn()的功能是:为一个偶数寻找两个素数,这两个素数之和等于该偶数,并将这两个素数通过形参指针传回主函数。 请改正函数 fun()中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include stdio.h #include math.h void fun(int a, int *b, int *c) int i,j,d,y; for (i=3;i=a/2;i=i+2) /*found*/

10、y=0; for (j=2;j=sqrt(double)i);j+) if (i%j=0) y=0; if (y=1) /*found*/ d=i-a; for (j-2;j=sqrt(double)d); j+) if (d%j=0) y=0; if (y=-1) *b=i; *c=d; main () int a,b,c; do printf(“/nInput a: “); scanf (“%d“, while (a%2); fun (a, printf (“/n/n%d=%d+%d/n“, a,b,c); (分数:30.00)填空项 1:_ (正确答案:错误:y=0; 正确:y=1:)解

11、析:(2)错误:d=i-a; 正确:d=a-i; 解析 这道题是历年的考题经典。也就是验证哥德巴赫猜想之变体,原来的思路是(任意一个大于等于 6 的偶数都可以分解为两个素数之和)n 为大于等于 6 的任一偶数,可分解为 n1 和 n2 两个数,分别检查 n1 和 n2 是否为素数,如都是,则为一组解。如 n1 不是素数,就不必再检查 n2 是否素数。先从 n1=3 开始,检验 n1 和 n2(n2=N-n1)是否素数。然后使 n1+2 再检验 n1,n2是否素数,直到 n1=n/2 为止。该题思路是与“经典猜想”是相同的。三、B编程题/B(总题数:1,分数:40.00)3.请编写一个函数 vo

12、id fun(char*ss),其功能是:将字符串 ss 中所有下标为偶数位置上的字母转化为大写(若该位置上不是字母,则不转换)。 例如,若输入 abc4Efg,则应输出 AbC4EfG。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #includeconio. h #includestdio. h void fun ( char *ss) main ( ) char tt51; clrscr (); printf(“Please enter an character string within

13、50 characters:/n“); gets (tt); printf (“/n/nAfter changing, the string/n %s“, tt); fun (tt); printf(“/nbecomes/n /%s“,tt); (分数:40.00)_正确答案:()解析:void fun ( char *ss) int i; for(i=0;ssi!=/0;i+) if(i%2=0 /*大写字母比相应的小写字母的 ASCII 码值小 32*/ 解析 从 C 语言的学习中我们知道,只要将小写字母减去 32 则转换成大写字母,将大写字母加上 32 则转成小写字母,该程序使用 if 语句实现该功能转换的。

展开阅读全文
相关资源
猜你喜欢
  • BS PD ISO TS 19337-2016 Nanotechnologies Characteristics of working suspensions of nano-objects for $ii$in $iv$ii$it$ir$io assays to evaluate inherent nano-object toxi city《纳米技术 评估纳米物体固有毒性的体外试验所.pdf BS PD ISO TS 19337-2016 Nanotechnologies Characteristics of working suspensions of nano-objects for $ii$in $iv$ii$it$ir$io assays to evaluate inherent nano-object toxi city《纳米技术 评估纳米物体固有毒性的体外试验所.pdf
  • BS PD ISO TS 21219-2-2014 Intelligent transport systems Traffic and travel information (TTI) via transport protocol experts group generation 2 (TPEG2) UML modelling rules《智能运输系统 利用第二代传输协议专家组 (TPEG.pdf BS PD ISO TS 21219-2-2014 Intelligent transport systems Traffic and travel information (TTI) via transport protocol experts group generation 2 (TPEG2) UML modelling rules《智能运输系统 利用第二代传输协议专家组 (TPEG.pdf
  • BS PD ISO TS 28560-4-2014 Information and documentation RFID in libraries Encoding of data elements based on rules from ISO IEC 15962 in an RFID tag with partitioned memory《信息与文献 图书馆中应用的无线射频识别技术.pdf BS PD ISO TS 28560-4-2014 Information and documentation RFID in libraries Encoding of data elements based on rules from ISO IEC 15962 in an RFID tag with partitioned memory《信息与文献 图书馆中应用的无线射频识别技术.pdf
  • BS S 150-1975 Specification for chromium-molybdenum-vanadium-niobium heat-resisting steel billets bars forgings and parts (930-1080 MPa) (Cr 10 5 Mo 0 6 V 0 2 Nb 0 3)《铬-钼-钒-铌-耐热钢坯、棒材、锻件及零件规范(930-.pdf BS S 150-1975 Specification for chromium-molybdenum-vanadium-niobium heat-resisting steel billets bars forgings and parts (930-1080 MPa) (Cr 10 5 Mo 0 6 V 0 2 Nb 0 3)《铬-钼-钒-铌-耐热钢坯、棒材、锻件及零件规范(930-.pdf
  • BS PD ISO IEC TR 20000-12-2016 Information technology Service management Guidance on the relationship between ISO IEC 20000-1 2011 and service management frameworks CMMI-SVC 《信息技术 .pdf BS PD ISO IEC TR 20000-12-2016 Information technology Service management Guidance on the relationship between ISO IEC 20000-1 2011 and service management frameworks CMMI-SVC 《信息技术 .pdf
  • BS PD ISO IEC TR 20007-2014 Information technology Cultural and linguistic interoperability Definitions and relationship between symbols icons animated icons pictograms characters .pdf BS PD ISO IEC TR 20007-2014 Information technology Cultural and linguistic interoperability Definitions and relationship between symbols icons animated icons pictograms characters .pdf
  • BS PD ISO IEC TR 29110-5-1-3-2017 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Software engineering Management and engineering guide Generic p.pdf BS PD ISO IEC TR 29110-5-1-3-2017 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Software engineering Management and engineering guide Generic p.pdf
  • BS PD ISO IEC TR 29110-5-6-1-2015 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Systems engineering Management and engineering guide Generic pr.pdf BS PD ISO IEC TR 29110-5-6-1-2015 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Systems engineering Management and engineering guide Generic pr.pdf
  • BS PD ISO IEC TR 29110-5-6-2-2014 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Systems engineering Management and engineering guide Generic pr.pdf BS PD ISO IEC TR 29110-5-6-2-2014 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Systems engineering Management and engineering guide Generic pr.pdf
  • 相关搜索

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

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