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

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

1、全国计算机二级 C语言上机试题 71+2015年及答案解析(总分:30.00,做题时间:90 分钟)1.给定程序中,函数 fun的功能是:将形参 s所指字符串中的所有数字字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作为函数值返回。 例如,s 所指字符串为:asd123fgh5#43df,处理后新字符串为:123543asdfgh#df。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。注意:源程序存放在考生文件夹下的 BLANK1.C中。 不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include #include #include

2、 char *fun(char *s) int i, j, k, n; char *p, *t; n=strlen(s)+1; t=(char*)malloc(n*sizeof(char); p=(char*)malloc(n*sizeof(char); j=0; k=0; for(i=0; i if(isdigit(si) /*found*/ p_1_=si; j+; else tk=si; k+; /*found*/ for(i=0; i_2.给定程序 MODI1.C中函数 fun的功能是:首先把 b所指字符串中的字符按逆序存放, 然后将 a所指字符串中的字符和 b所指字符串中的字符,按排

3、列的顺序交叉合并到 c所指数组中,过长的剩余字符接在 c所指数组的尾部。例如,当 a所指字符串中的内容为“abcdefg“,b 所指字符串中的内容为“1234“时,c 所指数组中的内容应该为“a4b3c2d1efg“;而当 a所指字符串中的内容为“1234“,b 所指字符串中的内容为“abcdefg“时,c 所指数组中的内容应该为“1g2f3e4dcba“。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include void fun( char *a, char *b, char *c )

4、 int i , j; char ch; i = 0; j = strlen(b)-1; /*found*/ while ( i j ) ch = bi; bi = bj; bj = ch; i+; j-; while ( *a | *b ) /*found*/ If ( *a ) *c = *a; c+; a+; if ( *b ) *c = *b; c+; b+; *c = 0; main() char s1100,s2100,t200; printf(“/nEnter s1 string : “);scanf(“%s“,s1); printf(“/nEnter s2 string : “

5、);scanf(“%s“,s2); fun( s1, s2, t ); printf(“/nThe result is : %s/n“, t ); (分数:10.00)_3.函数 fun的功能是:将 s所指字符串中下标为偶数同时 ASCII值为奇数的字符删除,s 所指串中剩余的字符形成的新串放在 t所指的数组中。 例如,若 s所指字符串中的内容为“ABCDEFG12345“,其中字符 C的 ASCII码值为奇数,在数组中的下标为偶数, 因此必须删除;而字符 1的 ASCII码值为奇数,在数组中的下标也为奇数,因此不应当删除,其它依此类推。 最后 t所指的数组中的内容应是“BDF12345“。

6、注意: 部分源程序存在文件 PROG1.C中。 请勿改动主函数 main和其它函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 给定源程序: #include #include void fun(char *s, char t) main() char s100, t100; printf(“/nPlease enter string S:“); scanf(“%s“, s); fun(s, t); printf(“/nThe result is: %s/n“, t); NONO(); (分数:10.00)_全国计算机二级 C语言上机试题 71+2015年答案解析(总分:30

7、00,做题时间:90 分钟)1.给定程序中,函数 fun的功能是:将形参 s所指字符串中的所有数字字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作为函数值返回。 例如,s 所指字符串为:asd123fgh5#43df,处理后新字符串为:123543asdfgh#df。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。注意:源程序存放在考生文件夹下的 BLANK1.C中。 不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include #include #include char *fun(char *s) int i, j, k, n;

8、 char *p, *t; n=strlen(s)+1; t=(char*)malloc(n*sizeof(char); p=(char*)malloc(n*sizeof(char); j=0; k=0; for(i=0; i if(isdigit(si) /*found*/ p_1_=si; j+; else tk=si; k+; /*found*/ for(i=0; i_正确答案:(第一处:函数中申请了两个内存空间,其 p是存放数字字符串,t 是存放非数字字符串,根据条件可知,p 依次存放数字字符串,其位置由 j来控制,所以应填:j。 第二处:利用 for循环再把 t中的内容依次追加到 p

9、中,其中 t的长度为 k,所以应填:k。 第三处:最后返回 p的首地址即可,所以应填:p。)解析:2.给定程序 MODI1.C中函数 fun的功能是:首先把 b所指字符串中的字符按逆序存放, 然后将 a所指字符串中的字符和 b所指字符串中的字符,按排列的顺序交叉合并到 c所指数组中,过长的剩余字符接在 c所指数组的尾部。例如,当 a所指字符串中的内容为“abcdefg“,b 所指字符串中的内容为“1234“时,c 所指数组中的内容应该为“a4b3c2d1efg“;而当 a所指字符串中的内容为“1234“,b 所指字符串中的内容为“abcdefg“时,c 所指数组中的内容应该为“1g2f3e4d

10、cba“。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include void fun( char *a, char *b, char *c ) int i , j; char ch; i = 0; j = strlen(b)-1; /*found*/ while ( i j ) ch = bi; bi = bj; bj = ch; i+; j-; while ( *a | *b ) /*found*/ If ( *a ) *c = *a; c+; a+; if ( *b ) *c = *

11、b; c+; b+; *c = 0; main() char s1100,s2100,t200; printf(“/nEnter s1 string : “);scanf(“%s“,s1); printf(“/nEnter s2 string : “);scanf(“%s“,s2); fun( s1, s2, t ); printf(“/nThe result is : %s/n“, t ); (分数:10.00)_正确答案:(第一处:应该判断 i是否小于 j,所以应改为:while(i。 第二处:if 错写成 If。)解析:3.函数 fun的功能是:将 s所指字符串中下标为偶数同时 ASCI

12、I值为奇数的字符删除,s 所指串中剩余的字符形成的新串放在 t所指的数组中。 例如,若 s所指字符串中的内容为“ABCDEFG12345“,其中字符 C的 ASCII码值为奇数,在数组中的下标为偶数, 因此必须删除;而字符 1的 ASCII码值为奇数,在数组中的下标也为奇数,因此不应当删除,其它依此类推。 最后 t所指的数组中的内容应是“BDF12345“。 注意: 部分源程序存在文件 PROG1.C中。 请勿改动主函数 main和其它函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 给定源程序: #include #include void fun(char *s, char t) main() char s100, t100; printf(“/nPlease enter string S:“); scanf(“%s“, s); fun(s, t); printf(“/nThe result is: %s/n“, t); NONO(); (分数:10.00)_正确答案:(void fun(char *s, char t) int i, j = 0 ; for(i = 0 ; i strlen(s) ; i+) if(!(i % 2) =0 tj = 0 ; )解析:

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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