【计算机类职业资格】二级C语言机试16及答案解析.doc

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

1、二级 C 语言机试 16 及答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充函数 fun(),该函数的功能是:依次取出字符串中所有的小写字母以形成新的字符串,并取代原字符串。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #includeconio.h void fun(char *s) int i=0; char *p=s; while(U 【1】 /U) if (*p=a U【2】 /U; p+

2、; si=U 【3】 /U; main() char str80; clrscr(); printf(“/nEnter a string:“); gets(str); printf(“/n/nThe string is:/%s/n“,str); fun(str); printf(“/n/nThe string of changing is:/%s/n“,str); (分数:30.00)填空项 1:_二、B改错题/B(总题数:1,分数:30.00)2.下列给定的程序中,函数 fun()的功能是;将 s 所指字符串中出现的 n 所指字符串全部替换成 t2 所指字符串,所形成的新的字符串放在 w 所

3、指的数组中。在此处,要求 t1 和 t2 所指字符串的长度相同。例如:当 s 所指字符串中所指的内容为 abcdabfab,t1 所指字符串中的内容为 ab,t2 所指字符串中的内容为 99时,结果在 w 所指的数组中的内容应为 99cd99f99。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include conio.h #include stdio.h #include string.h /*found*/ int fun (char *s, char *t1, char *t2, char *w) i

4、nt i; char *p,*r,*a; strcpy(w,s); while (*w) p=w; r=t1; /*found*/ while (r) if (*r= =*p) r+;p+; else break; if (*r= =/0) a=w; r=t2; /*found*/ while (*r)*a=*r;a+;r+ w+=strlen(t2); else w+; main() char s100,t1100,t2100,w100; clrscr(); printf(“/nPlease enter string S: “); scanf(“%s“,s); printf(“/nPleas

5、eentersubstring 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“,w); else printf(“Error : strlen(t2)/n“); (分数:30.00)填空项 1:_三、B编程题/B(总题数:1,分数:40.00)3.编写函数 fun(),函数的功能是:根据以下公式计算 s,计算结果作为函数值返

6、回;n 通过形参传入。 S=1+1/(1+2)+1/(1+2+3)+1/(1+2+3+n) 例如:若 n 的值为 11 时,函数的值为 1.833333。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #include conio.h #include stdio.h #include string.h float fun(int n) main() int n; float s; clrscr(); printf(“/nPlease enter N: “); scanf(“%d“, s=fun(n

7、); printf(“The result is:%f/n “ , s); (分数:40.00)_二级 C 语言机试 16 答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充函数 fun(),该函数的功能是:依次取出字符串中所有的小写字母以形成新的字符串,并取代原字符串。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #includeconio.h void fun(char *s) int i=0;

8、 char *p=s; while(U 【1】 /U) if (*p=a U【2】 /U; p+; si=U 【3】 /U; main() char str80; clrscr(); printf(“/nEnter a string:“); gets(str); printf(“/n/nThe string is:/%s/n“,str); fun(str); printf(“/n/nThe string of changing is:/%s/n“,str); (分数:30.00)填空项 1:_ (正确答案:1 *p 2 i+ 3 /0)解析:解析 填空 1:while 循环的循环条件是指针 p

9、 所指的字符不是/0,也就是说,当处理到字符串最后的结束标记字符 /0时,while 循环结束。填空 2:如果指针 p 所指的字符为小写字母,则将这个字符存于原字符串 s 中,同时,下标自加 1,为下一次存放做准备。填空 3:在取出所有小写字母并存于原字符串 s 后,要注意在最后加上字符串结束标志符/0。二、B改错题/B(总题数:1,分数:30.00)2.下列给定的程序中,函数 fun()的功能是;将 s 所指字符串中出现的 n 所指字符串全部替换成 t2 所指字符串,所形成的新的字符串放在 w 所指的数组中。在此处,要求 t1 和 t2 所指字符串的长度相同。例如:当 s 所指字符串中所指的

10、内容为 abcdabfab,t1 所指字符串中的内容为 ab,t2 所指字符串中的内容为 99时,结果在 w 所指的数组中的内容应为 99cd99f99。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include conio.h #include stdio.h #include string.h /*found*/ int fun (char *s, char *t1, char *t2, char *w) int i; char *p,*r,*a; strcpy(w,s); while (*w) p=w

11、; r=t1; /*found*/ while (r) if (*r= =*p) r+;p+; else break; if (*r= =/0) a=w; r=t2; /*found*/ while (*r)*a=*r;a+;r+ w+=strlen(t2); else w+; main() char s100,t1100,t2100,w100; clrscr(); printf(“/nPlease enter string S: “); scanf(“%s“,s); printf(“/nPleaseentersubstring t1: “); scanf (“%s“, t1); printf

12、(“/nPlease enter substring t2: “); scanf (“%s“,t2); if (strlen(t1)= =strlen(t2) fun (s,t1,t2,w); printf(“/nThe result is : %s/n“,w); else printf(“Error : strlen(t2)/n“); (分数:30.00)填空项 1:_ (正确答案:错误:int fun(char *s,char *t1,char *t2, char *w))解析:正确:void fun(char *s,char *t1,char *t2, char *w) (2) 错误:w

13、hile(r) 正确:while(*r) (3) 错误:r+ 正确:r+; 解析 在 int fun(char *s,char *t1,char *t2, char *w)中,用 int 型定义指针数组。ANSI 标准要求动态分配系统返回 void 指针。 void 指针具有一般性,它们可以指向任何类型的数据。但目前绝大多数 C 编译所提供的这类函数都返回 char 指针。无论以上两种情况的哪一种,都需要强制类型转换的方法把 char 指针转换成所需的类型。该程序段应该是 void fun(char *s,char *t1, char *t2, char *w),另外,while(r)和 r+

14、都是简单的逻辑和语法错误,只要加强了 C 语言的基础,这样的错误明显是“送分”的。三、B编程题/B(总题数:1,分数:40.00)3.编写函数 fun(),函数的功能是:根据以下公式计算 s,计算结果作为函数值返回;n 通过形参传入。 S=1+1/(1+2)+1/(1+2+3)+1/(1+2+3+n) 例如:若 n 的值为 11 时,函数的值为 1.833333。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #include conio.h #include stdio.h #include st

15、ring.h float fun(int n) main() int n; float s; clrscr(); printf(“/nPlease enter N: “); scanf(“%d“, s=fun(n); printf(“The result is:%f/n “ , s); (分数:40.00)_正确答案:()解析:float fun(int n) int i,s1=0; float s=0.0; for(i=1;i=n;i+) s1=s1+i; /*求每一项的分母*/ s=s+1.0/s1; /*求多项式的值*/ return s; 解析 本题中用 s1 来表示式中每一项的分母,而每一项的分母都是其前一项分母加项数。注意由于 s1 定义成一个整型,所以在 s=s+1.0/s1 中不能把 1.0写成 1。

展开阅读全文
相关资源
猜你喜欢
  • NC 62-27-1986 National Elactroenergetic System Ttiermoeleotric Plants General Requirements for Technologioal Projection Electric Connection Main Diagrams《国家电能系统 热电安装 技术项目的一般要求 电连接主.pdf NC 62-27-1986 National Elactroenergetic System Ttiermoeleotric Plants General Requirements for Technologioal Projection Electric Connection Main Diagrams《国家电能系统 热电安装 技术项目的一般要求 电连接主.pdf
  • NC 62-30-1986 National Electroenergetic System Thermoelectrlc Plants Secondary and Auxiliary Clrcults General Requlrements for the Technological Projection《国家电能系统 热电安装 二级和辅助电路 技术项目.pdf NC 62-30-1986 National Electroenergetic System Thermoelectrlc Plants Secondary and Auxiliary Clrcults General Requlrements for the Technological Projection《国家电能系统 热电安装 二级和辅助电路 技术项目.pdf
  • NC 62-31-1986 National Electroenergetic System Power Stations Substations Cable Installations and Auxiliary Installations General Requirements for Technological Projection《国家电能系统 电.pdf NC 62-31-1986 National Electroenergetic System Power Stations Substations Cable Installations and Auxiliary Installations General Requirements for Technological Projection《国家电能系统 电.pdf
  • NC 62-35-1987 Electric Industry wires and Cables for Underrrround Distribution and Connection Quality Specifications《电气工业 电线和电缆地下分配和连接质量规格》.pdf NC 62-35-1987 Electric Industry wires and Cables for Underrrround Distribution and Connection Quality Specifications《电气工业 电线和电缆地下分配和连接质量规格》.pdf
  • NC 62-36-1987 Electric Industry Wires and Cables with an Insulation up to 1 kV Mechanical Tests《电气工业 电线和电缆绝缘达到1千伏 机械测试》.pdf NC 62-36-1987 Electric Industry Wires and Cables with an Insulation up to 1 kV Mechanical Tests《电气工业 电线和电缆绝缘达到1千伏 机械测试》.pdf
  • NC 62-38-1987 Electric Industry Bare Wires and Cables Mechanical Tests《电气行业 裸线和电缆 机械测试》.pdf NC 62-38-1987 Electric Industry Bare Wires and Cables Mechanical Tests《电气行业 裸线和电缆 机械测试》.pdf
  • NC 62-39-1987 Electric Industry Thermoelectric Stations General Requirements for Technoloqical Projection Turbines and Auxiliary Equipment《电气行业热电站 透平机和辅助设备技术要求》.pdf NC 62-39-1987 Electric Industry Thermoelectric Stations General Requirements for Technoloqical Projection Turbines and Auxiliary Equipment《电气行业热电站 透平机和辅助设备技术要求》.pdf
  • NC 62-40-1988 Electric Industry National Electroenergetic System Thermoelectric Stations General Requirements for Technological Designing Hydrotechnics《电气行业 国家电能系统热电站 技术设计要求 水力学》.pdf NC 62-40-1988 Electric Industry National Electroenergetic System Thermoelectric Stations General Requirements for Technological Designing Hydrotechnics《电气行业 国家电能系统热电站 技术设计要求 水力学》.pdf
  • NC 62-41-1988 Electric Industry National Electroenérgetic System Thermoeiectric Stations Electric Connection Diagrams o£ Plant Services General Requirements for Technological Desig.pdf NC 62-41-1988 Electric Industry National Electroenérgetic System Thermoeiectric Stations Electric Connection Diagrams o£ Plant Services General Requirements for Technological Desig.pdf
  • 相关搜索
    资源标签

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

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