【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷444及答案解析.doc

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

1、国家二级 C语言机试(操作题)模拟试卷 444及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.下列给定程序中,函数 fun的功能是计算下式 直到 (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中函数 fun的功能是:将 s所指字符串的正序和反序进行连接,形成的新串放在 t所指的数组中。 例如,当 s所指字符串为“ABCD”时,t 所指字符串中的内容应为“ABCDDCBA”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include

2、 conioh #include stdioh #include stringh /*found*/void fun(char s,char t) int i , d; d=Str1en(s); for(i=0;i d;i+) ti=si; for(i=0;i d;i+) td+i=sd 一 1一 i;/*found*/ t2*d一 1=/0;main() char s100,t100; printf(“inPlease enter string s:“); scanf(“s“,s); fun(s,t); printf(“/nTbe result is:skn“,t);(分数:2.00)_三、

3、程序设计题(总题数:1,分数:2.00)3.编写函数 fun,其功能是:将 S所指字符串中除了下标为奇数同时 ASCII码值也为奇数的字符之外,其余的所有字符全部删除,串中剩余字符所形成的一个新串放在 t所指的数组中。 例如,若 S所指字符串的内容为 “ABCDEFGl2345”,其中字符 A的 ASCII码值为奇数,但所在元素的下标为偶数,因此需要删除;而字符 1的 ASCII码值为奇数,所在数组中的下标也为奇数,因此不应当删除,其他依此类推。最后t所指数组中的内容应为“135”。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编

4、写的若干语句。 试题程序:#include conioh #include stdioh #include stringh void fun(char * s,char t)msin()char s100,t100; printf(“inPlease enter string s:“);Scanf(“s“,s); fun(s,t);printf(“knThe result is:s/n“,t);(分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 444答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.下列给定程序中,函数 fun的功能是计算

5、下式 直到 (分数:2.00)_正确答案:(正确答案:(1)0 (2)i+或+i 或 i+=1或 i=i+l (3)20*i)解析:解析:填空 1:循环变量 i从 1开始参加运算,但是在每次循环的开始 i都进行自加 1操作,故 i应赋初值为 0。 填空 2:循环变量 i自增 1运算。 填空 3:根据公式确定表达式通项。注意 x为 double型,故应将 i变为 double型再进行运算。二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中函数 fun的功能是:将 s所指字符串的正序和反序进行连接,形成的新串放在 t所指的数组中。 例如,当 s所指字符串为“ABCD”时,t 所指字符串

6、中的内容应为“ABCDDCBA”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include conioh #include stdioh #include stringh /*found*/void fun(char s,char t) int i , d; d=Str1en(s); for(i=0;i d;i+) ti=si; for(i=0;i d;i+) td+i=sd 一 1一 i;/*found*/ t2*d一 1=/0;main() char s100,t100; printf(“inPlease

7、enter string s:“); scanf(“s“,s); fun(s,t); printf(“/nTbe result is:skn“,t);(分数:2.00)_正确答案:(正确答案:(1) void fun(char *s,char*t) (2)t2*d=/0;或 td+i=/0;或 t2*d=0;或 td+i=0;)解析:解析:(1)从调用函数来看,函数传递的是数组,所以函数的形参应为指针。 (2)循环结束后回文字符的个数为 2*d个,因为数组下标是从 0开始的,所以最后一个字符的下标为 2*d一 1,在最后一个字符的后面加上结束符/0,因此为 t2*d=/0;。三、程序设计题(总

8、题数:1,分数:2.00)3.编写函数 fun,其功能是:将 S所指字符串中除了下标为奇数同时 ASCII码值也为奇数的字符之外,其余的所有字符全部删除,串中剩余字符所形成的一个新串放在 t所指的数组中。 例如,若 S所指字符串的内容为 “ABCDEFGl2345”,其中字符 A的 ASCII码值为奇数,但所在元素的下标为偶数,因此需要删除;而字符 1的 ASCII码值为奇数,所在数组中的下标也为奇数,因此不应当删除,其他依此类推。最后t所指数组中的内容应为“135”。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。

9、 试题程序:#include conioh #include stdioh #include stringh void fun(char * s,char t)msin()char s100,t100; printf(“inPlease enter string s:“);Scanf(“s“,s); fun(s,t);printf(“knThe result is:s/n“,t);(分数:2.00)_正确答案:(正确答案:void fun (char*s,char t) int i,j =0,n; n= str1en (s); for(i=0;i n;i+) if(i2)&(si2) tj+=si;/*将下标为奇数同时 ASCII码值为奇数的字符放入数组 t中*/ tj=/0; /*最后加上结束标识符*/ )解析:解析:本题要求除了下标为奇数同时 ASCII码值也为奇数的字符,其余的所有字符都删除,即要留下下标为奇数同时 ASCII码值也为奇数的字符。所以 if的条件语句应为:if(i2 1=0&si2!=0)。

展开阅读全文
相关资源
猜你喜欢
  • GOST 26 010-1980 Unified system of standards for instrument-making Measuring and automation devices Input and output frequency electric continuous signals《仪器制作标准的统一系统 测量与自动化装置 电连续信.pdf GOST 26 010-1980 Unified system of standards for instrument-making Measuring and automation devices Input and output frequency electric continuous signals《仪器制作标准的统一系统 测量与自动化装置 电连续信.pdf
  • GOST 26 011-1980 Measuring and automation devices Input and output current and voltage continuous signals《自动化仪表与装置 连续输出和输入电流和电压信号》.pdf GOST 26 011-1980 Measuring and automation devices Input and output current and voltage continuous signals《自动化仪表与装置 连续输出和输入电流和电压信号》.pdf
  • GOST 26 012-1994 Measuring and automation devices Hydraulic input and output signals《自动化仪表与装具 输入和输出液压信号》.pdf GOST 26 012-1994 Measuring and automation devices Hydraulic input and output signals《自动化仪表与装具 输入和输出液压信号》.pdf
  • GOST 26 013-1981 Measurement and automation means Input and output electrical signals with discrete change of parameters《测量和自动化措施 参数离散变化的输入和输出的电信号》.pdf GOST 26 013-1981 Measurement and automation means Input and output electrical signals with discrete change of parameters《测量和自动化措施 参数离散变化的输入和输出的电信号》.pdf
  • GOST 26 014-1981 Measurement and automation means Input and output electric coding signals《测量和自动化措施 电编码输入和输出信号》.pdf GOST 26 014-1981 Measurement and automation means Input and output electric coding signals《测量和自动化措施 电编码输入和输出信号》.pdf
  • GOST 26 015-1981 Measuring and automation devices Pneumatic input and output signals《测量与自动化装置 气动输入和输出信号》.pdf GOST 26 015-1981 Measuring and automation devices Pneumatic input and output signals《测量与自动化装置 气动输入和输出信号》.pdf
  • GOST 26 020-1980 Types for means of measuring and automation Inscription and main dimensions《测量和自动化措施类型 标记和主尺寸规格》.pdf GOST 26 020-1980 Types for means of measuring and automation Inscription and main dimensions《测量和自动化措施类型 标记和主尺寸规格》.pdf
  • GOST 26 201 1-1994 CAMAC Organization of multi-crate systems Specification of the branch-highway and CAMAC crate controller type A1《CAMAC系统 多机箱系统的组织》.pdf GOST 26 201 1-1994 CAMAC Organization of multi-crate systems Specification of the branch-highway and CAMAC crate controller type A1《CAMAC系统 多机箱系统的组织》.pdf
  • GOST 26 201 2-1994 CAMAC Serial highway interface system《CAMAC系统 接口系统的串行总线》.pdf GOST 26 201 2-1994 CAMAC Serial highway interface system《CAMAC系统 接口系统的串行总线》.pdf
  • 相关搜索

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

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