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

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

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

2、cludestdio.h #define MAX 20 void 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, str6MAX; system(“CLS“); for(i=0; i6; i+) pi=stri; printf(“/nEnter 6 s

3、tring(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); (分数:40.00)_三、程序设计题(总题数:1,分数:30.00)3.请编写函数 proc(),它的功能是:求出 str 所指字符串中指定字符的个数,并返回此值。 例如,若输入字符串 12341234123,输入字符 4,则输出 2。 注意:部分源程序给出如下。 请勿改动 main()函

4、数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h #define N 81 int 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 cha

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

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

7、cmp(pstr+i), (pstr+j)0) p=*(pstr+i); *(pstr+i)=*(pstr+j); /*found* *(pstr+j)=*p; void main() int i; char *p6, str6MAX; 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

8、i=0; i6; i+) printf(“%s/n“, pi); (分数:40.00)_正确答案:()解析:(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)”;根据

9、程序可知,要交换的是字符串的首地址而不是字符串的内容,因此,“*(pstr+j)=*p”应改为“*(pstr+j)=p”。三、程序设计题(总题数:1,分数:30.00)3.请编写函数 proc(),它的功能是:求出 str 所指字符串中指定字符的个数,并返回此值。 例如,若输入字符串 12341234123,输入字符 4,则输出 2。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h #define N

10、 81 int 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); (分数:30.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 中存放字符串中指定字符的个数,最后返回给主函数。

展开阅读全文
相关资源
猜你喜欢
  • ASD-STAN PREN 3330-1989 Aerospace Series Steel FE-PL45 Annealed Bar and Wire De Less Than or Equal to 40 mm for Prevailing Torque Nuts (Issue P 1)《航空航天系列 预置扭矩的螺母用De≤40mm的FE-PL45钢退火.pdf ASD-STAN PREN 3330-1989 Aerospace Series Steel FE-PL45 Annealed Bar and Wire De Less Than or Equal to 40 mm for Prevailing Torque Nuts (Issue P 1)《航空航天系列 预置扭矩的螺母用De≤40mm的FE-PL45钢退火.pdf
  • ASD-STAN PREN 3332-2003 Aerospace Series Aluminium Alloy AL-P7475-T762 Clad Sheet and Strip 1 0 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 3)《航空航天系列 1 0mm≤a≤6.pdf ASD-STAN PREN 3332-2003 Aerospace Series Aluminium Alloy AL-P7475-T762 Clad Sheet and Strip 1 0 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 3)《航空航天系列 1 0mm≤a≤6.pdf
  • ASD-STAN PREN 3333-2003 Aerospace Series Aluminium Alloy AL-P7475-T762 Sheet and Strip 0 6 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 3)《航空航天系列 0 6mm≤a≤6mm的铝合.pdf ASD-STAN PREN 3333-2003 Aerospace Series Aluminium Alloy AL-P7475-T762 Sheet and Strip 0 6 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 3)《航空航天系列 0 6mm≤a≤6mm的铝合.pdf
  • ASD-STAN PREN 3334-1988 Aerospace Series Aluminium Alloy (7050) Solution Treated Controlled Stretched and Artificially Aged (T7651) Plate 6 Less Than or Equal to a Less Than or Equ.pdf ASD-STAN PREN 3334-1988 Aerospace Series Aluminium Alloy (7050) Solution Treated Controlled Stretched and Artificially Aged (T7651) Plate 6 Less Than or Equal to a Less Than or Equ.pdf
  • ASD-STAN PREN 3335-2003 Aerospace Series Aluminium Alloy AL-P7475-O2 Sheet for Superplastic Forming (SPF) 0 8 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 3)《航空.pdf ASD-STAN PREN 3335-2003 Aerospace Series Aluminium Alloy AL-P7475-O2 Sheet for Superplastic Forming (SPF) 0 8 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 3)《航空.pdf
  • ASD-STAN PREN 3336-1999 Aerospace Series Aluminium Alloy AL-P7150-T651 Plate 6mm Less Than a Less Than or Equal to 40mm (Edition P 3)《航空航天系列 6mm<a≤40mm的铝合金AL-P7150-T651厚板材 第P3版》.pdf ASD-STAN PREN 3336-1999 Aerospace Series Aluminium Alloy AL-P7150-T651 Plate 6mm Less Than a Less Than or Equal to 40mm (Edition P 3)《航空航天系列 6mm<a≤40mm的铝合金AL-P7150-T651厚板材 第P3版》.pdf
  • ASD-STAN PREN 3337-1988 Aerospace Series Aluminium Alloy (7010) Solution Treated and Artificially Aged (T74511) Extruded Bars and Sections (a or D) Less Than or Equal to 130 mm wit.pdf ASD-STAN PREN 3337-1988 Aerospace Series Aluminium Alloy (7010) Solution Treated and Artificially Aged (T74511) Extruded Bars and Sections (a or D) Less Than or Equal to 130 mm wit.pdf
  • ASD-STAN PREN 3338-2003 Aerospace Series Aluminium Alloy AL-P7050-T74511 Extruded Bar and Section a or D Less Than or Equal to 150 mm with Peripheral Coarse Grain Control (Edition .pdf ASD-STAN PREN 3338-2003 Aerospace Series Aluminium Alloy AL-P7050-T74511 Extruded Bar and Section a or D Less Than or Equal to 150 mm with Peripheral Coarse Grain Control (Edition .pdf
  • ASD-STAN PREN 3339-1998 Aerospace Series Aluminium Alloy AL-P7010-T76 Die Forgings a Less Than or Equal to 200 mm (Edition P 2)《航空航天系列 a≤150mm的铝合金AL-P7010-T76模锻件 第P2版》.pdf ASD-STAN PREN 3339-1998 Aerospace Series Aluminium Alloy AL-P7010-T76 Die Forgings a Less Than or Equal to 200 mm (Edition P 2)《航空航天系列 a≤150mm的铝合金AL-P7010-T76模锻件 第P2版》.pdf
  • 相关搜索

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

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