【计算机类职业资格】二级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。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN ISO 14644-10-2013 Cleanrooms and associated controlled environments - Part 10 Classification of surface cleanliness by chemical concentration (ISO 14644-10 2013) German vers.pdf DIN EN ISO 14644-10-2013 Cleanrooms and associated controlled environments - Part 10 Classification of surface cleanliness by chemical concentration (ISO 14644-10 2013) German vers.pdf
  • DIN EN ISO 14644-14-2017 Cleanrooms and associated controlled environments - Part 14 Assessment of suitability for use of equipment by airborne particle concentration (ISO 14644-14.pdf DIN EN ISO 14644-14-2017 Cleanrooms and associated controlled environments - Part 14 Assessment of suitability for use of equipment by airborne particle concentration (ISO 14644-14.pdf
  • DIN EN ISO 14644-2-2016 Cleanrooms and associated controlled environments - Part 2 Monitoring to provide evidence of cleanroom performance related to air cleanliness by particle co.pdf DIN EN ISO 14644-2-2016 Cleanrooms and associated controlled environments - Part 2 Monitoring to provide evidence of cleanroom performance related to air cleanliness by particle co.pdf
  • DIN EN ISO 14644-3-2006 Cleanrooms and associated controlled environments - Part 3 Test methods (ISO 14644-3 2005) English version of DIN EN ISO 14644-3 2006-03《洁净室和相关控制环境 第3部分 试验方.pdf DIN EN ISO 14644-3-2006 Cleanrooms and associated controlled environments - Part 3 Test methods (ISO 14644-3 2005) English version of DIN EN ISO 14644-3 2006-03《洁净室和相关控制环境 第3部分 试验方.pdf
  • DIN EN ISO 14644-4-2003 Cleanrooms and associated controlled environments - Part 4 Design construction and start up (ISO 14644-4 2001) German version EN ISO 14644-4 2001《洁净室和相关控制环境.pdf DIN EN ISO 14644-4-2003 Cleanrooms and associated controlled environments - Part 4 Design construction and start up (ISO 14644-4 2001) German version EN ISO 14644-4 2001《洁净室和相关控制环境.pdf
  • DIN EN ISO 14644-5-2005 Cleanrooms and associated controlled environments - Part 5 Operations (ISO 14644-5 2004) German version EN ISO 14644-5 2004《洁净室和相关控制环境 第5部分 操作》.pdf DIN EN ISO 14644-5-2005 Cleanrooms and associated controlled environments - Part 5 Operations (ISO 14644-5 2004) German version EN ISO 14644-5 2004《洁净室和相关控制环境 第5部分 操作》.pdf
  • DIN EN ISO 14644-6-2007 Cleanrooms and associated controlled environments - Part 6 Vocabulary (ISO 14644-6 2007) Trilingual version EN ISO 14644-6 2007《无菌室和相关控制环境 第6部分 词汇》.pdf DIN EN ISO 14644-6-2007 Cleanrooms and associated controlled environments - Part 6 Vocabulary (ISO 14644-6 2007) Trilingual version EN ISO 14644-6 2007《无菌室和相关控制环境 第6部分 词汇》.pdf
  • DIN EN ISO 14644-7-2005 Cleanrooms and associated controlled environments - Part 7 Separative devices (clean air hoods gloveboxes isolators and mini-environments) (ISO 14644-7 2004.pdf DIN EN ISO 14644-7-2005 Cleanrooms and associated controlled environments - Part 7 Separative devices (clean air hoods gloveboxes isolators and mini-environments) (ISO 14644-7 2004.pdf
  • DIN EN ISO 14644-8-2013 Cleanrooms and associated controlled environments - Part 8 Classification of air cleanliness by chemical concentration (ACC) (ISO 14644-8 2013) German versi.pdf DIN EN ISO 14644-8-2013 Cleanrooms and associated controlled environments - Part 8 Classification of air cleanliness by chemical concentration (ACC) (ISO 14644-8 2013) German versi.pdf
  • 相关搜索

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

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