[计算机类试卷]国家二级C语言机试(操作题)模拟试卷567及答案与解析.doc

上传人:boatfragile160 文档编号:498531 上传时间:2018-11-29 格式:DOC 页数:7 大小:31KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷567及答案与解析.doc_第1页
第1页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷567及答案与解析.doc_第2页
第2页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷567及答案与解析.doc_第3页
第3页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷567及答案与解析.doc_第4页
第4页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷567及答案与解析.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 567及答案与解析 一、程序填空题 1 下列给定程序中,函数 fun的功能是:将形参 S所指字符串中的所有字母字符顺序前移,其他字符顺序后移,处理后将新字符串的首地址作为函数值返回。 例如,若 s所指字符串为 “asdl23fgh543df”,处理后新字符串为“asdfghdfl23543”。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构 ! 试 题程序: #include stdio h #include stdlib h #include string h c

2、har*fun(char *s) int i, j, k, n; char*p, *t; n=strlen(s)+1; t=(char*)malloc(n*si zeof(char); p=(char*)malloc(n *si zeof(char); j=0; k=0; for(i=0; i n; i+) if(si =a)&(si =z)|(si =A)&(si =Z) *found* tj=【 1】 ; j+; else Pk=si; k+; *found* for(i=0; i 【 2】 ; i+) tj+i=pi; *found* tj+k=【 3】 ; return t; main

3、) char s80; printf(“Please input: “); Scanf(“ s“, s); printf f“ nThe result is: s n“, fun(S); 二、程序修改题 2 下列给定程序中,函数 fun的功能是:将 S所指字符串中最后一次出现的与 tl所指字符串相同的子串替换成 t2所指字符串,所形成的新串放在 W所指的数组中。要求 t1和 t2所指字符串的长度相同。 例如,当 s所指字符串中的内容为 “abcdabfabc”, t1所指 串中的内容为 “ab”, t2所指子串中的内容为 “99”时,结果在 w所指的数组中的内容应为 “abcdabt99c”

4、 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include conio h #include stdio h #include string h void fun(char*s, char*t1, char*t2, char*w) char*p, *r, *a; strcpy(w, s); *found* while(w) p=w; r=t1; while(*r) *found* IF(*r=*p) r+; p+; else break; if(*r= 0) a=w; w+; r=t2; while(*r

5、) *a=* r; a+; r+; main() char s100, t1100, t2 100, wi00; printf(“ nPlease enter string S: “); scanf(“ s”, s); printf(“ nPlease enter substring t1: “); scanf(“ s“, t1); printf(“ nPlease enter substring t2: “); Scanf(“ s“, t2); if(strlen(t1)=strlen(t2) fun(S, t1, t2, W); printf(“ nThe result is: s n“,

6、 w); else printf(“ nError: strlen(t1)!=strlen(t2) n“); 三、程序设计题 3 编写函数 fun,其功能是:将 s所指字符串中 ASCII码值为奇数的字符删除,剩余字符形成的新串放在 t所 指数组中。 例如,若 s所指字符串中的内容为 “ABCDEFGl2345”,其中字符 A的 ASCII码值为奇数,字符 1的 ASCII码值也为奇数,都应当删除,其他依此类推。最后 t所指的数组中的内容应是 “BDF24”。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序

7、 #include conio h #include Stdio h #include string h void fun(char*s, char t) main() char s100, t100, Msg =“Please enter string s: “; printf(Msg); scanf(“ s“, s); fun(s, t); printf(“ nThe resuit is: s n“, t); 国家二级 C语言机试(操作题)模拟试卷 567答案与解析 一、程序填空题 1 【正确答案】 (1)si (2)k (3) 0或 0 【试 题解析】 填空 1:将字符串 s中所有字母

8、元素赋给数组 t。 填空 2:字符串中所有非字母元素放到字母元素后面,所以 i的取值范围是 0 k。 填空 3:最后给字符串加入结束标识 0。 二、程序修改题 2 【正确答案】 (1)while(*w) (2)1f(*r=*p) 【试题解析】 (1)此处要判断的是值的真假,而不是地址,所以改为 while(*w)。 (2)c语言中关键字区分大小写,只需运行程序,就可以根据错误提示找到。 三、程序设计题 3 【正确答案】 void fun(char*s, char t) int i, j=0, n; n=strlon(s); *遍历整个数组 * for(i=0; i n; i+) *如果元素的 ASCII码值为偶数 * if(si 2=0) *将元素保存到 t中 * tj=si; j+; tj= 0; 【试题解析】 要删除 ASCII码值为奇数的字符,也就是要保留 ASCII码值为偶数的字符,由于最终是要求出剩余字符形成的新串,所以本题的算法是对原字符串从头到尾扫描,找出 ASCII码值为偶数的字符并依次存入数组。

展开阅读全文
相关资源
猜你喜欢
  • 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