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

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

1、二级 C 语言机试-18 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)1.请补充 main 函数,该函数的功能是:计算三名学生学科的平均成绩。例如,当 scoreNM=83.5,82,86,65,67,80,91.5,84, 99,95,90,95,86,95,97 时,五门学科的平均分为:84.5 89.5 85.3 86.3 86.3。注意:部分源程序给出如下。请勿改动主函数 main 和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。试题程序:# includestdio, h#define N 3#de

2、fine M 5main ( )int i,j;static float score N M= 83.5, 82,86,65,67, 80,91.5,84,99,95,90, 95, 86, 95, 97 ;static float bbN;clrscr ();for ( i=0; iM; i+)bbi=0.0;for(i=0;i 【1】 ;i+)for(j=0;j 【2】 ;j+)bb j+=score i j;for (i=0; iM; i+)print f (“ /nsubject%d/taverage=%5.1 f“,i+1, 【3】 );return 0;(分数:30.00)填空项

3、1:_二、改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:统计字符串 substr 在字符串 srt 中出现的次数。例如,若字符串为 aaas 1 kaaas,子字符串为 as,则应输出 2。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序:#include stdio.hfun (char *str, char *substr)int i, j, k, num=0;/*found*/for (i=0, str i, i+)for (j=i, k=O; substr k=str j ;

4、 k+, j + )if (substr k+l= /0)num+;break; return num;main ( )char str80,substr80;printf(“Input a string: “);gets (str);printf(“Input a sbustring: “);gets (substr);printf (“%d/n “, fun (str, substr) );(分数:30.00)填空项 1:_三、编程题(总题数:1,分数:40.00)3.假定输入的字符串中只包含字母和*号。请编写函数 fun(),它的功能是:删除字符串中所有的*号。在编写函数时,不得使用 C

5、 语言中提供的字符串函数。例如,若字符串中的内容为*A*BC*DEF*G*,删除后,字符串中的内容则应当是 ABCDEFG。注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。试题程序:# includeconio, h# includestdio, hvoid fun (char *a)main ( )char s81;printf (“Enter a string: /n“);gets (s);fun(s);printf (“The string after deleted: /n“);puts (s);(分数:4

6、0.00)_二级 C 语言机试-18 答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)1.请补充 main 函数,该函数的功能是:计算三名学生学科的平均成绩。例如,当 scoreNM=83.5,82,86,65,67,80,91.5,84, 99,95,90,95,86,95,97 时,五门学科的平均分为:84.5 89.5 85.3 86.3 86.3。注意:部分源程序给出如下。请勿改动主函数 main 和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。试题程序:# includestdio, h#define N

7、 3#define M 5main ( )int i,j;static float score N M= 83.5, 82,86,65,67, 80,91.5,84,99,95,90, 95, 86, 95, 97 ;static float bbN;clrscr ();for ( i=0; iM; i+)bbi=0.0;for(i=0;i 【1】 ;i+)for(j=0;j 【2】 ;j+)bb j+=score i j;for (i=0; iM; i+)print f (“ /nsubject%d/taverage=%5.1 f“,i+1, 【3】 );return 0;(分数:30.00

8、填空项 1:_ (正确答案:1N 2M (3)bbi/N)解析:解析 填空 1:由循环体中的 scoreij可以推断出,变量 i 的取值范围是从 0 到 N-1。填空2:由循环体中的 scoreij也可以推断出,变量 j 的取值范围是从 0 到 M-1。填空 3:各科的平均分等于各科的总分除以学生人数,此时数组 bb 中保存的是各科的总分,所以要除以 N 得到各科的平均分。二、改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:统计字符串 substr 在字符串 srt 中出现的次数。例如,若字符串为 aaas 1 kaaas,子字符串为 as,则应输出 2。

9、请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序:#include stdio.hfun (char *str, char *substr)int i, j, k, num=0;/*found*/for (i=0, str i, i+)for (j=i, k=O; substr k=str j ; k+, j + )if (substr k+l= /0)num+;break; return num;main ( )char str80,substr80;printf(“Input a string: “);gets (s

10、tr);printf(“Input a sbustring: “);gets (substr);printf (“%d/n “, fun (str, substr) );(分数:30.00)填空项 1:_ (正确答案:错误:for(i=0,srti,i+) 正确:for(i=0;stri;i+))解析:解析 从字符串 s 中找出子字符串的方法是:从第 1 个字符开始,对字符串进行遍历;若 s 串的当前字符等于 t 串的第 1 个字符,两字符串的指针自动加 1,继续比较下一个字符;若比较至字符串的结尾,则跳出循环;若 s 串的字符和 t 串的字符不对应相同,则继续对 s 串的下一个字符进行处理。

11、三、编程题(总题数:1,分数:40.00)3.假定输入的字符串中只包含字母和*号。请编写函数 fun(),它的功能是:删除字符串中所有的*号。在编写函数时,不得使用 C 语言中提供的字符串函数。例如,若字符串中的内容为*A*BC*DEF*G*,删除后,字符串中的内容则应当是 ABCDEFG。注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。试题程序:# includeconio, h# includestdio, hvoid fun (char *a)main ( )char s81;printf (“Enter a

12、 string: /n“);gets (s);fun(s);printf (“The string after deleted: /n“);puts (s);(分数:40.00)_正确答案:(void fun(char. *a)int i, j=0;for (i=0;a i !=/0;i+)if (ai 1=*)a j+=a i; /*若不是要删除的字符*则留下*/a j =/ 0; /*最后加上字符结束符*/)解析:解析 同样的问题我们在前面也碰到过,本题中是删除多余字符(*)。所以用循环从字符串的开始往后一个一个进行比较,若不是要删除的字符(用 ifai!=*)来控制)则留下。注意下标变量 j 要从0 开始,最后还要加上字符串结束符/0。

展开阅读全文
相关资源
猜你喜欢
  • ONORM M 6208-1978 Specifications jor the requirements for waste water to be discharged from slaughter-houses and meat processing enterprises《屠宰场和肉类加工企业的污水排放要求规范》.pdf ONORM M 6208-1978 Specifications jor the requirements for waste water to be discharged from slaughter-houses and meat processing enterprises《屠宰场和肉类加工企业的污水排放要求规范》.pdf
  • ONORM M 6209-1984 Specification for the requirements for waste water to be discharged from cooling Systems《冷却系统污水排放的要求规范》.pdf ONORM M 6209-1984 Specification for the requirements for waste water to be discharged from cooling Systems《冷却系统污水排放的要求规范》.pdf
  • ONORM M 6210-1988 Requirements for the characteristics of waste water to be discharged from Photographie laboratories and graphical shops《摄影实验室和绘画商店污水排放特点要求》.pdf ONORM M 6210-1988 Requirements for the characteristics of waste water to be discharged from Photographie laboratories and graphical shops《摄影实验室和绘画商店污水排放特点要求》.pdf
  • ONORM M 6211-1981 Requirements for the characteristics of waste water to be discharged from plants producing Sauerkraut and pickles《植物生产酸菜和咸菜的污水排放特点要求》.pdf ONORM M 6211-1981 Requirements for the characteristics of waste water to be discharged from plants producing Sauerkraut and pickles《植物生产酸菜和咸菜的污水排放特点要求》.pdf
  • ONORM M 6212-1983 Requirements jor the characteristics of water to be discharged from hospitals and other health institutions《医院和其他卫生机构的污水排放特点要求》.pdf ONORM M 6212-1983 Requirements jor the characteristics of water to be discharged from hospitals and other health institutions《医院和其他卫生机构的污水排放特点要求》.pdf
  • ONORM M 6214-1990 Requirements for the characteristics of waste water to be discharged from laquering painting and varnishing plants and shops《涂漆 喷漆及上漆工厂和商店污水排放的特点要求》.pdf ONORM M 6214-1990 Requirements for the characteristics of waste water to be discharged from laquering painting and varnishing plants and shops《涂漆 喷漆及上漆工厂和商店污水排放的特点要求》.pdf
  • ONORM M 6215-1991 Requirements for the characteristlcs of water in indoor and artificial outdoor swimming pools《室内和人工室外游泳池的水质特点要求》.pdf ONORM M 6215-1991 Requirements for the characteristlcs of water in indoor and artificial outdoor swimming pools《室内和人工室外游泳池的水质特点要求》.pdf
  • ONORM M 6216-2000 Water treatment plants for indoor and artificial outdoor swimming pools《室内和人工室外游泳池用水处理厂》.pdf ONORM M 6216-2000 Water treatment plants for indoor and artificial outdoor swimming pools《室内和人工室外游泳池用水处理厂》.pdf
  • ONORM M 6217-2001 Internal supervision of water treatment plants for indoor and artificial outdoor swimming pools and hot whirlpools with partial load《用于室内和人工室外游泳池及分载浴缸的水处理厂内部监督》.pdf ONORM M 6217-2001 Internal supervision of water treatment plants for indoor and artificial outdoor swimming pools and hot whirlpools with partial load《用于室内和人工室外游泳池及分载浴缸的水处理厂内部监督》.pdf
  • 相关搜索

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

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