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

上传人:livefirmly316 文档编号:498527 上传时间:2018-11-29 格式:DOC 页数:5 大小:33KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷563及答案与解析.doc_第1页
第1页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷563及答案与解析.doc_第2页
第2页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷563及答案与解析.doc_第3页
第3页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷563及答案与解析.doc_第4页
第4页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷563及答案与解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 563及答案与解析 一、程序填空题 1 下列给定程序中,函数 fun的功能是:将形参 S所指字符串中下标为奇数的字符按 ASCII码大小递增排序,并将排序后下标为奇数的字符取出,存入形参 P所指字符数组中,形成一个新串。 例如,形参 s所指的字符为 “baawrskjghzlicda”,执行后 P所指字符数组中的字符串应为 “aachjlsw”。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行 或删行,也不得更改程序的结构 ! 试题程序: #include stdio h void fun(c

2、har* s, char *p) int i , j , n , x , t; n=0; for(i=0; si!= 0; i+)n+; for(i=1; i n一 2; i=i+2) *found* 【 1】 ; *found* for(j=【 2】 +2; j n; j=j+2) if(st sj)t=j; if(t!=1) x=si; si=st; st=x; for(i=1, j=0; i n; i=i+2, j+) Pj=si; *found* pj=【 3】 ; main() char s80=“baawrskjgh zlicda“, p50; printf(“ nThe orig

3、inal string is: s n“, s); fun(s, p); printf(“nThe result is: sn“, p); 二、程序修改题 2 下列给定程序中,函数 fun的功能是:用下面的公式求 的近似值,直到最后一项的绝对值小于指定的数 (参数 num)为止。 例如,程序运行后,输入 0 0001,则程序输出 3 1414。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdlib h #include math h #include stdio h float fun(f

4、loat num) int s; float n , t , pi; t=1; pi=0; n=1; s=1;*found* while(t =num) pi=pi+t; n=n+2; s=-s;*found* t=s n; pi=pi*4; return pi; void main() float n1, n2; system(“CLS“); printf(“Enter a float numbet: “); scanf(“ f“, &n1); n2=fun(n1); printf(“ 6 4 f n“, n2); 三、程序设计题 3 编写函数 fun,其功能是:删除一个字符串中指定下标的字

5、符。其中, a指向原字符串,删除指定字符后的字符串存放在 b所指的数组中, n中存放指定的下标。 例如,输入一个字符串 “World”,然后输入 3,则调用该函数后的结果为 “Word”。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdlib h #include stdio h #include conio h #define LEN 20 void fun(char a, char b, int n) void main() char strlLEN, str2LEN; in

6、t n; system(“CLS“); printf(“Enter the string: n“); gets(Str1); printf(“Enter the position of the string deleted: “); scanf(“ d“, n); fun(str1, str2, n); printf(“The new string is: s n“, str2); 国家二级 C语言机试(操作题)模拟试卷 563答案与解析 一、程序填空题 1 【正确答案】 (1)t=i (2)i或 t (3) 0或 0 【试题解析】 本题中第 1个 for循环的 作用是得到字符串的长度,第 2

7、个 for循环的作用是对下标为奇数的字符按 ASCII:码大小排序,最后将排好序的字符取出。 填空 1:取出字符串中下标为奇数的字符,所以将下标 i赋值给中间变量 t。 填空 2:此处 for循环语句的作用是实现对下标为奇数的元素进行排序操作,所以循环变量初值应填入 i或 t;。 填空 3:将下标为奇数的字符取出后,存入 p所指的数组中,最后不要忘记在数组最后加入字符串结束标识 0。 二、程序修改题 2 【正确答案】 (1)while(fabs(t) =num) (2)t=s n; 【 试题解析】 (1)函数 fun中 while语句的作用是,当新的一项大于给定参数时,循环累计计算 s的值。题

8、目要求最后一项的绝对值小于给定参数,因此循环条件应当是 while串,所以每循环一次要使指针向后移动一个位置,而不是将指针所指的元素加 1。 (2)变量 t用来存放最后一项的值,因为每一项均为 1或一 1除以一个数,所以此处应使用除法运算符 “ ”。 三、程序设计题 3 【正确答案】 voild fun(char a, char b, int n) int i, k=0; for(i=0; ai!= 0; i+) if(i!=n) *将不是指定 下标的字符存入数组 b中 * bk+=ai; bk= 0; *在字符串最后加上结束标识 * 【试题解析】 本题要求删除字符串中指定下标的字符,即把非指定下标的字符保留,所以 if语句条件表达式的内容是 if(i!=n)。字符串最后不要忘记加上字符串结束标识 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