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

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

1、二级 C语言机试-244 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)请补充函数 proc(),该函数的功能是:计算下面公式的值(k50):(分数:30.00)填空项 1:_填空项 1:_填空项 1:_二、改错题(总题数:1,分数:30.00)1.下列给定程序中,函数 proc()的功能是:用冒泡法对 6个字符串按由小到大的顺序进行排序。请修改程序中的错误,使它能得到正确结果。注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。试题程序:#includestring.h#includestdlib.h#includecon

2、io.h#includestdio.h#define MAX 20void proc(char * pstr6)int i, j;char *p;for(i=0; i5; i+)for(j=i+1; j6; j+)/*found*if(strcmp(pstr+i), (pstr+j)0)p=*(pstr+i);*(pstr+i)=*(pstr+j);/*found*(pstr+j)=*p;void main()int i;char *p6, str6 MAX;system(“CLS“);for(i=0; i6; i+)pi=stri;printf(“/nEnter 6 string(1 str

3、ing at each line): /n“);for(i=0; i6; i+)scanf(“%s“, pi);proc(p);printf(“The strings after sorting: /n“);for(i=0; i6; i+)printf(“%s/n“, pi);(分数:30.00)填空项 1:_三、编程题(总题数:1,分数:40.00)2.请编写函数 proc(),它的功能是:求出 str所指字符串中指定字符的个数,并返回此值。例如,若输入字符串 12341234123,输入字符 4,则输出 2。注意:部分源程序已给出。请勿改动主函数 main和其他函数中的任何内容。试题程序:

4、includestdlib.h#includeconio.h#includestdio.h#define N 81int proc(char * str, char c)void main()char aN, ch;system(“CLS“);printf(“/nPlease enter a string: “);gets(a);printf(“/nPlease enter a char: “);ch=getchar();printf(“/nThe number of the char is: %d /n“, proc(a, ch);(分数:40.00)_二级 C语言机试-244 答案解析(

5、总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)请补充函数 proc(),该函数的功能是:计算下面公式的值(k50):(分数:30.00)填空项 1:_ (正确答案:1)解析:填空项 1:_ (正确答案:k=n)解析:填空项 1:_ (正确答案:m*=f/p)解析:解析 题目中要求的是各项元素的乘积,因此其初始值为。因此1处填 1;变量 k表示的是乘积的项数,故其一定要小于等于 n,因此2处填 k=n; 由函数 proc可知,变量 f表示各项的分子,变量 p表示各项的分母,因此3处填 m*=f/p。二、改错题(总题数:1,分数:30.00)1.下列给定程序中

6、函数 proc()的功能是:用冒泡法对 6个字符串按由小到大的顺序进行排序。请修改程序中的错误,使它能得到正确结果。注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。试题程序:#includestring.h#includestdlib.h#includeconio.h#includestdio.h#define MAX 20void proc(char * pstr6)int i, j;char *p;for(i=0; i5; i+)for(j=i+1; j6; j+)/*found*if(strcmp(pstr+i), (pstr+j)0)p=*(pstr+i);*

7、pstr+i)=*(pstr+j);/*found*(pstr+j)=*p;void main()int i;char *p6, str6 MAX;system(“CLS“);for(i=0; i6; i+)pi=stri;printf(“/nEnter 6 string(1 string at each line): /n“);for(i=0; i6; i+)scanf(“%s“, pi);proc(p);printf(“The strings after sorting: /n“);for(i=0; i6; i+)printf(“%s/n“, pi);(分数:30.00)填空项 1:_

8、正确答案:(1)错误:if(strcmp(pstr+i), (pstr+j)0)正确:if(strcmp(*(pstr+i), *(pstr+j)0)(2)错误:*(pstr+j)= *p;正确:*(pstr+j)=p;)解析:解析 变量 pstr表示的是字符串数组的首地址,pstr+i 表示的是字符串首地址偏移量为 i处的地址。程序中要比较的是字符,因此,if(strcmp(pstr+i), (pstr+j)0)应改为 if(strcmp(*(pstr+i),*(pstr+j)0);根据程序可知,要交换的是字符串的首地址而不是字符串的内容,因此,*(pstr+j)=*p应改为*(pstr+

9、j)=p。三、编程题(总题数:1,分数:40.00)2.请编写函数 proc(),它的功能是:求出 str所指字符串中指定字符的个数,并返回此值。例如,若输入字符串 12341234123,输入字符 4,则输出 2。注意:部分源程序已给出。请勿改动主函数 main和其他函数中的任何内容。试题程序:#includestdlib.h#includeconio.h#includestdio.h#define N 81int proc(char * str, char c)void main()char aN, ch;system(“CLS“);printf(“/nPlease enter a str

10、ing: “);gets(a);printf(“/nPlease enter a char: “);ch=getchar();printf(“/nThe number of the char is: %d /n“, proc(a, ch);(分数:40.00)_正确答案:(int proc(char*str, char c)int i=0; /i是放与 c相同的字符的个数的变量for(; *str!=/0; str+)if(*str=c) /str所指字符串中指定字符的个数i+; return i;)解析:解析 求出 str所指字符串中指定字符的个数,可以通过将 str所指字符串中每一个字符与指定字符相比较,变量 i中存放字符串中指定字符的个数,最后返回给主函数。

展开阅读全文
相关资源
猜你喜欢
  • ASTM E1885-2004 Standard Test Method for Sensory Analysis&8212 Triangle Test《感官分析的标准试验方法 三角试验》.pdf ASTM E1885-2004 Standard Test Method for Sensory Analysis&8212 Triangle Test《感官分析的标准试验方法 三角试验》.pdf
  • ASTM E1885-2004(2011) Standard Test Method for Sensory AnalysisTriangle Test《传感技术分析 三角试验的标准试验方法》.pdf ASTM E1885-2004(2011) Standard Test Method for Sensory AnalysisTriangle Test《传感技术分析 三角试验的标准试验方法》.pdf
  • ASTM E1885-2018 Standard Test Method for Sensory Analysis&x2014 Triangle Test.pdf ASTM E1885-2018 Standard Test Method for Sensory Analysis&x2014 Triangle Test.pdf
  • ASTM E1886-2005 Standard Test Method for Performance of Exterior Windows Curtain Walls Doors and Impact Protective Systems Impacted by Missile(s) and Exposed to Cyclic Pressure Dif.pdf ASTM E1886-2005 Standard Test Method for Performance of Exterior Windows Curtain Walls Doors and Impact Protective Systems Impacted by Missile(s) and Exposed to Cyclic Pressure Dif.pdf
  • ASTM E1886-2013 Standard Test Method for Performance of Exterior Windows Curtain Walls Doors and Impact Protective Systems Impacted by Missile(s) and Exposed to Cyclic Pressure Dif.pdf ASTM E1886-2013 Standard Test Method for Performance of Exterior Windows Curtain Walls Doors and Impact Protective Systems Impacted by Missile(s) and Exposed to Cyclic Pressure Dif.pdf
  • ASTM E1886-2013a Standard Test Method for Performance of Exterior Windows Curtain Walls Doors and Impact Protective Systems Impacted by Missile(s) and Exposed to Cyclic Pressure Di.pdf ASTM E1886-2013a Standard Test Method for Performance of Exterior Windows Curtain Walls Doors and Impact Protective Systems Impacted by Missile(s) and Exposed to Cyclic Pressure Di.pdf
  • ASTM E1888 E1888M-2007 Standard Practice for Acoustic Emission Examination of Pressurized Containers Made of Fiberglass Reinforced Plastic with Balsa Wood Cores《带巴沙(Balsa)木芯的玻璃纤维增强.pdf ASTM E1888 E1888M-2007 Standard Practice for Acoustic Emission Examination of Pressurized Containers Made of Fiberglass Reinforced Plastic with Balsa Wood Cores《带巴沙(Balsa)木芯的玻璃纤维增强.pdf
  • ASTM E1888 E1888M-2012 Standard Practice for Acoustic Emission Examination of Pressurized Containers Made of Fiberglass Reinforced Plastic with Balsa Wood Cores《用软木芯玻璃纤维增强塑料制成的压力容器.pdf ASTM E1888 E1888M-2012 Standard Practice for Acoustic Emission Examination of Pressurized Containers Made of Fiberglass Reinforced Plastic with Balsa Wood Cores《用软木芯玻璃纤维增强塑料制成的压力容器.pdf
  • ASTM E1888 E1888M-2017 Standard Practice for Acoustic Emission Examination of Pressurized Containers Made of Fiberglass Reinforced Plastic with Balsa Wood Cores《用巴沙木芯玻璃纤维增强塑料制成的压力容.pdf ASTM E1888 E1888M-2017 Standard Practice for Acoustic Emission Examination of Pressurized Containers Made of Fiberglass Reinforced Plastic with Balsa Wood Cores《用巴沙木芯玻璃纤维增强塑料制成的压力容.pdf
  • 相关搜索

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

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