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

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

1、国家二级 C语言机试(操作题)模拟试卷 370及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是:判断形参 s所指字符串是否是 “回文 ”(Palindrome),若是,函数返回值为 1;不是,函数返回值为 0。 “回文 ”是正读和反读都一样的字符串 (不区分大小写字母 )。 例如, LEVEL和 Level是 “回文 ”,而 LEVLEV不是。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1 C中。 不得增行或删行, 也不得更改程序的结构 ! 1 #include stdio h 2 #include s

2、tring h 3 #include ctype h 4 int fun(char *s) 5 char *1p, *rp; 6 *found* 7 1p=_1_; 8 rp=s+strlen(s)-1; 9 while(toupper(*1p)=toupper(*rp) (1p rp) 10 *found* 11 1p+; rp_2_; 12 *found* 13 if(1p rp) _3_; 14 else return 1; 15 16 main() 17 char s81; 18 printf(Enter a string: ); scanf( s, s); 19 if(fun(s)p

3、rintf( n s is a Palindrome n n, s); 20 else printf( n s isnt a Palindrome n n, s); 21 二、程序修改题 2 给定程序 MODI1 C中 fun函数的功能是:根据整型形参 m,计算如下公式的值。 例如,若主函数中输入 5,则应输出 -0 283333。 请改正函数 fun中的错误或在横线处填上适当的内容并把横线删除,使它能计算出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 !1 #include stdio h 2 double fun(int m)3 4 double t=1

4、 0; 5 int i; 6 for(i=2; i=m; i+)7 *found* 8 t=1 0-1 i; 9 *found* 10 _; 11 12 main()13 14 int m; 15 printf(nPlease enter 1 integer numbers: n); 16 scanf( d, m); 17 printf( n nThe result is 1f n, fun(m); 18 三、程序设计题 3 假定输入的字符串中只包含字母和 *号。请编写函数 fun,它的功能是:除了尾部的 *号之外,将字符串中其他木号全部删除。形参 p已指向字符串中最后的一个字母。在编写函数时

5、,不得使用 c语言提供的字符串函数。 例如, 字符串中的内容为: *A*BC*DEF*G*,删除后,字符串中的内容应当是:ABCDEFG*。 注意:部分源程序在文件 PROG1 C中。 请勿改动主函数 main和其他函数中的任何内容, 仅在函数 fun的花括号中填入你编写的若干语句。 1 #include stdio h 2 void fun(char *a, char *p) 3 4 5 main() 6 char s81, *t ; 7 void NONO(); 8 printf(Enter a string: n); gets(s); 9 t=s; 10 while( *t)t+; 11

6、 t-; 12 while(*t=*)t-; 13 fun(s, t); 14 printf(The string after deleted: n); puts(s); 15 NONO(); 16 17 void NONO() 18 *本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 * 19 FTLE *in, *out; 20 int i; char s81, *t; 21 in=fopen(in dat, r); 22 out=fopen(out dat, w); 23 for(i=0; i 10; i+) 24 fscanf(in, s, s); 25 t=s; 26 w

7、hile(*t)t+; 27 t-; 28 while(*t=*)t-; 29 fun(s, t); 30 fprintf(out, s n, s); 31 32 fclose(in); 33 fclose(out); 国家二级 C语言机试(操作题)模拟试卷 370答案与解析 一、程序填空题 1 【正确答案】 (1)s (2)- (3)return 0 【试题解析】 第一空: “rp=s+strlen(s)-1; ”可知 rp指向最后一个元素,因此 1p是指向第一个元素,因此第一空应为 “s”。 第二空: “1p+; rp_2_; ”1p往后移动, rp应该往前移动,故第二空处应为 “-”。

8、第三空: “if(1p rp)”成立说明 1p和 rp比较没有比较到字符串的最中间的字符,也就是说 s字符串不是回文,因此第三空处的应为 “return 0”。 二、程序修改题 2 【正确答案】 (1)t=t-1 0 i;或 t-=1 0 i;或 t-=(double)1 i; (2)return t; 【试题解析】 函数的功能是计算公式的值。 (1)第一个标识下的 “t=1 0-1 i; ”语句对题干中给出的多项式的求值,而根据题干中多项式的特点,多项式应该是“t=t-1 0 i;”。 (2)根据函数定义, fun函数应该具有返回值,第二个标识下的填空应该是 “return t; ”返回多项

9、式的值。 三、程序设计题 3 【正确答案】 1 char *q=a; 2 int j=0; 3 while(*q 5 q+; 6 7 while(*p)aj+=*p+; 8 aj= 0; 【试题解析】 (1)首先,主函数中使指针移到字符串的最后一个字符,对字符串由串尾开始进行操作。 (2)然后,指针由尾开始向头移动,查找第一个非 “*”号字符,指针 t指向后一个非 “*”,即从最后一个非 “*”,字符开始的字符都不需要删除,将前面的其他 “*”号全部删除后,将尾部的 “*”字符往前移动即可。 (3)确定了字符数组的最后一个字符非 “*”后,调用 fun函数,在 fun函数中,将原串 中由起始位置的字符开始到最后一个非 “*”逐个查询该字符是否是 “*”字符,如果是则删除,并将后面的字符往前移动;然后将 t之后的字符移动到前面,最后在字符串的后面添加 “ 0”即可。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 3707-1991 Aerospace Series Headless Threaded Plugs Installation Holes Issue P 1《航空航天系列.无头线性插头安装孔》.pdf AECMA PREN 3707-1991 Aerospace Series Headless Threaded Plugs Installation Holes Issue P 1《航空航天系列.无头线性插头安装孔》.pdf
  • AECMA PREN 3708-001-1996 Aerospace Series Modular Interconnection Systems Terminal Junction Systems Part 001  Technical Specification Edition P 2《航空航天系列 模块化互连系统的终端连接系统.第001 部分 技术规格.pdf AECMA PREN 3708-001-1996 Aerospace Series Modular Interconnection Systems Terminal Junction Systems Part 001 Technical Specification Edition P 2《航空航天系列 模块化互连系统的终端连接系统.第001 部分 技术规格.pdf
  • AECMA PREN 3708-002-1996 Aerospace Series Modular Interconnection Systems Terminal Junction Systems Part 002  Perfomance Specification Edition P 2《航空航天系列 模块化互连系统的终端连接系统.第002 部分 技术规.pdf AECMA PREN 3708-002-1996 Aerospace Series Modular Interconnection Systems Terminal Junction Systems Part 002 Perfomance Specification Edition P 2《航空航天系列 模块化互连系统的终端连接系统.第002 部分 技术规.pdf
  • AECMA PREN 3708-003-1996 Aerospace Series Modular Interconnection Systems Terminal Junction Systems Part 003  Removable Feedback Modules Version Sealed Product Standard Edition P 2.pdf AECMA PREN 3708-003-1996 Aerospace Series Modular Interconnection Systems Terminal Junction Systems Part 003 Removable Feedback Modules Version Sealed Product Standard Edition P 2.pdf
  • AECMA PREN 3708-004-1996 Aerospace Series Modular Interconnection Systems Terminal Junction Systems Part 004  Removable Feedback Modules Version Unsealed Product Standard Edition P.pdf AECMA PREN 3708-004-1996 Aerospace Series Modular Interconnection Systems Terminal Junction Systems Part 004 Removable Feedback Modules Version Unsealed Product Standard Edition P.pdf
  • AECMA PREN 3708-005-1996 Aerospace Series Modular Interconnection Systems Terminal Junction Systems Part 005  Frames with Accessories for Feedback Modules Version Sealed and Unseal.pdf AECMA PREN 3708-005-1996 Aerospace Series Modular Interconnection Systems Terminal Junction Systems Part 005 Frames with Accessories for Feedback Modules Version Sealed and Unseal.pdf
  • AECMA PREN 3709-2005 Aerospace Series Wrenches and Sockets Bi-Hexagonal Technical Specification Edition P 2《航空航天系列.十二角扳手和套筒.技术规范.》.pdf AECMA PREN 3709-2005 Aerospace Series Wrenches and Sockets Bi-Hexagonal Technical Specification Edition P 2《航空航天系列.十二角扳手和套筒.技术规范.》.pdf
  • AECMA PREN 3710-1990 Aerospace Series Sockets Bi-Hexagonal Technical Specification Issue P 1《航空航天系列.十二角扳手技术规范.》.pdf AECMA PREN 3710-1990 Aerospace Series Sockets Bi-Hexagonal Technical Specification Issue P 1《航空航天系列.十二角扳手技术规范.》.pdf
  • AECMA PREN 3711-1990 Aerospace Series Wrench-Double Ended Bi-Hexagonal Straight Cranked Offset Issue P 1《航空航天系列.双头十二角油曲槟扳手》.pdf AECMA PREN 3711-1990 Aerospace Series Wrench-Double Ended Bi-Hexagonal Straight Cranked Offset Issue P 1《航空航天系列.双头十二角油曲槟扳手》.pdf
  • 相关搜索

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

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