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

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

1、二级 C 语言机试 82 及答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充函数 fun(),该函数的功能是:返回字符数组中指定子符的个数,指定字符从键盘输入。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include stdio.h #define N 80 int fun (char s,char ch) int i=0, n=0; while(U 【1】 /U) if(U 【2】 /U) n+; i+; U 【3】 /

2、U; main ( ) int n; char strN, ch; clrscr (); printf (“/nInput a string: /n“); gets (str); printf (“/nInput a charactor: /n“ ; scanf (“%c“, n=fun (str, ch); printf(“/nnumber of %c:%d“, ch, n); (分数:30.00)填空项 1:_二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中函数 fun()的功能是;先将在字符串 s 中的字符按逆序存放到 t 串中,然后把 s 中的字符按正序连接到 t 串

3、的后面。例如:当 s 中的字符串为 ABCDE 时,则 t 中的字符串应为 EDCBAABCDE。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include conio.h #include stdio.h #include string.h void fun (char *s, char *t ) int i,sl; sl=strlen(s); for (i=0;isl;i+) ti=ssl-1; for (i=0; isl; i+) /*found* t sl+i=s i; t 2*sl-/0; mai

4、n ( ) char s100, t100; clrscr(); printf(“/nPlease enter string s: “); scanf (“%s“, s); fun (s,t); printf (“The result is: %s/n“,t); (分数:30.00)填空项 1:_三、B编程题/B(总题数:1,分数:40.00)3.编写一个函数,该函数可以统计一个长度为 2 的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为 asd asasdfg asd as zx67 asd mklo,子字符串为 as,则应当输出 6。 注意:部分源程序给出如下。 请勿改动主函数

5、 main 和具他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #include conio.h #include stdio.h #include string.h int fun(char *str, char *substr) main ( ) char str81,substr3; int n; clrscr (); printf (“输入主字符串 “); gets (str); printf (“输入子字符串“); gets (substr); puts (str); puts (substr); n=fun (shr, substr); prin

6、tf(“n=%d/n “,n); (分数:40.00)_二级 C 语言机试 82 答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充函数 fun(),该函数的功能是:返回字符数组中指定子符的个数,指定字符从键盘输入。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include stdio.h #define N 80 int fun (char s,char ch) int i=0, n=0; while(U 【1】 /U) i

7、f(U 【2】 /U) n+; i+; U 【3】 /U; main ( ) int n; char strN, ch; clrscr (); printf (“/nInput a string: /n“); gets (str); printf (“/nInput a charactor: /n“ ; scanf (“%c“, n=fun (str, ch); printf(“/nnumber of %c:%d“, ch, n); (分数:30.00)填空项 1:_ (正确答案:1 si或者 si!= /0 2 si=ch 3 return n)解析:解析 填空 1:while 循环的条件是

8、当前参加比较的字符不为/0,即还没有到字符串的最后一个字符。填空 2:如果当前字符等于指定字符,则统计个数的变量 n 加 1。填空 3:函数要求返回字符数组中指定字符的个数,所以函数要返回 n。二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中函数 fun()的功能是;先将在字符串 s 中的字符按逆序存放到 t 串中,然后把 s 中的字符按正序连接到 t 串的后面。例如:当 s 中的字符串为 ABCDE 时,则 t 中的字符串应为 EDCBAABCDE。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序

9、 #include conio.h #include stdio.h #include string.h void fun (char *s, char *t ) int i,sl; sl=strlen(s); for (i=0;isl;i+) ti=ssl-1; for (i=0; isl; i+) /*found* t sl+i=s i; t 2*sl-/0; main ( ) char s100, t100; clrscr(); printf(“/nPlease enter string s: “); scanf (“%s“, s); fun (s,t); printf (“The r

10、esult is: %s/n“,t); (分数:30.00)填空项 1:_ (正确答案:错误: ti=ss1-1; 正确: ti=ss1-1-i;)解析:解析 该题也是几个循环语句的嵌套使用,难度并不大,重要的足要读懂程序,题目中赋值语句ti=ss1-1;并不能完成累计循环,所以正确的应该是 ti=ss1-1-i;。三、B编程题/B(总题数:1,分数:40.00)3.编写一个函数,该函数可以统计一个长度为 2 的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为 asd asasdfg asd as zx67 asd mklo,子字符串为 as,则应当输出 6。 注意:部分源程序给出如

11、下。 请勿改动主函数 main 和具他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #include conio.h #include stdio.h #include string.h int fun(char *str, char *substr) main ( ) char str81,substr3; int n; clrscr (); printf (“输入主字符串 “); gets (str); printf (“输入子字符串“); gets (substr); puts (str); puts (substr); n=fun (shr, sub

12、str); printf(“n=%d/n “,n); (分数:40.00)_正确答案:()解析:int fun(char *str, char *substr) int i, j=0; for(i=0;stri+1!=/0;i+) /*如果一个长度为 2 的子字符串在主字符串中出现一次,则 j+1, 如此 循环*/ if (str i=substr 0 return j; /*返回子字符串在主字符串中出现的次数*/ 解析 该题中subsu 只有两个字符,所以可以用 if 语句来直接进行判断。要注意 if()中 str 组的下标为 i 和 i+1,即比较当前字符及其以后的一个字符是否分别与 substr 中的字符对应相同,若都相同则表示出现了一次。

展开阅读全文
相关资源
猜你喜欢
  • STAS SR EN 646-1996 Paper and board intended to come into contact with foodstuffs -Determination of colour fastness of dyed paper and board《预计和食品有关的纸和纸板中染色纸和纸板的颜色坚牢度的测定 》.pdf STAS SR EN 646-1996 Paper and board intended to come into contact with foodstuffs -Determination of colour fastness of dyed paper and board《预计和食品有关的纸和纸板中染色纸和纸板的颜色坚牢度的测定 》.pdf
  • STAS SR EN 71-1-1995 SAFETY OF TOYS Part 1 Specification for mechanical and physical properties《玩具安全 第1部分:机械和物理性能规范 》.pdf STAS SR EN 71-1-1995 SAFETY OF TOYS Part 1 Specification for mechanical and physical properties《玩具安全 第1部分:机械和物理性能规范 》.pdf
  • STAS SR EN 717-2 C1-1996 Wood - based panels - Determinations of formaldehyde release Part 2 Formaldehyde release by the gas analysis method《木制人造板 甲醛释放量的测定 第2部分:气体分析法分析甲醛释放》.pdf STAS SR EN 717-2 C1-1996 Wood - based panels - Determinations of formaldehyde release Part 2 Formaldehyde release by the gas analysis method《木制人造板 甲醛释放量的测定 第2部分:气体分析法分析甲醛释放》.pdf
  • STAS SR EN 717-2-1995 Wood-based panels - Determinations of formaldehyde release Part 2 Formaldehyde release by the gas analysis method《木制人造板 甲醛释放的测定 第2部分:气体分析法分析甲醛释放》.pdf STAS SR EN 717-2-1995 Wood-based panels - Determinations of formaldehyde release Part 2 Formaldehyde release by the gas analysis method《木制人造板 甲醛释放的测定 第2部分:气体分析法分析甲醛释放》.pdf
  • STAS SR EN 719-1995 Welding coordination Tasks and responsibilities《焊接协调 任务和责任》.pdf STAS SR EN 719-1995 Welding coordination Tasks and responsibilities《焊接协调 任务和责任》.pdf
  • STAS SR EN 73-1995 Wood preservatives Accelerated ageing of treated wood prior to biological testing Evaporative ageing procedure《木材防腐剂 生物测定前处理木材加速成熟蒸发成熟过程 》.pdf STAS SR EN 73-1995 Wood preservatives Accelerated ageing of treated wood prior to biological testing Evaporative ageing procedure《木材防腐剂 生物测定前处理木材加速成熟蒸发成熟过程 》.pdf
  • STAS SR EN 78-1996 Methods of testing windows Form of test report《测试窗体的方法 测试报告的格式 》.pdf STAS SR EN 78-1996 Methods of testing windows Form of test report《测试窗体的方法 测试报告的格式 》.pdf
  • STAS SR EN 803-1996 Plastics pipirig systems - Injection-moulded thermoplastics fittings for elastic sealing ring type joints for pressure pipirig - Test method for resistence to a《.pdf STAS SR EN 803-1996 Plastics pipirig systems - Injection-moulded thermoplastics fittings for elastic sealing ring type joints for pressure pipirig - Test method for resistence to a《.pdf
  • STAS SR EN 84-1993 Wood preservatives Accelerated ageing of treated wood prior to biological testing Leaching procedure《木材防腐剂 生物测试的之前进行已处理木材的加速成熟 过滤程序 》.pdf STAS SR EN 84-1993 Wood preservatives Accelerated ageing of treated wood prior to biological testing Leaching procedure《木材防腐剂 生物测试的之前进行已处理木材的加速成熟 过滤程序 》.pdf
  • 相关搜索

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

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