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

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

1、二级 C 语言-333 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:求 m!。 例如 10!=3628800。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h #includeconio.h void main() int i, m; long f=1; system(“CLS“); printf(“Input m:“)

2、 scanf(“%d“, 1); for( 2; i=m; i+) 3; printf(“%d!=%1d/n“, m, f); (分数:30.00)二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中,函数 proc()的功能是:求 S 的值。设 S=(22/(1*3)*(42/(3*5)*(62/(5*7) *(2k)2/(2k-1)*(2k-1) 例如,当 k 为 20 时,函数的值应为 1.551759。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdio.h #inc

3、ludeconio.h #includestdio.h #includemath.h /*found* proc(int k) int n; float s, w, p, q; n=1; s=1.0; while(n=k) w=2.0*n; p=w-1.0; q=w+1.0; s=s*w*w/p/q; n+; /*found* return s void main() system(“CLS“); printf(“%f/n“, proc(20); (分数:40.00)_三、程序设计题(总题数:1,分数:30.00)3.请编写一个函数,用来删除字符串中的所有空格。 例如,输入 abc de f

4、gh,则输出为 abcdefgh。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includectype.h #includeconio.h #includestdiib.h void proc(char*str) void main() char str81; system(“CLS“); printf(“Input a string: “); gets(str); puts(str); proc(str); printf(“*str: %s/n“, str

5、); (分数:30.00)_二级 C 语言-333 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:求 m!。 例如 10!=3628800。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h #includeconio.h void main() int i, m; long f=1; system(“CLS“); print

6、f(“Input m:“); scanf(“%d“, 1); for( 2; i=m; i+) 3; printf(“%d!=%1d/n“, m, f); (分数:30.00)解析: float s, w, p, q; n=1; s=1.0; while(n=k) w=2.0*n; p=w-1.0; q=w+1.0; s=s*w*w/p/q; n+; /*found* return s void main() system(“CLS“); printf(“%f/n“, proc(20); (分数:40.00)_正确答案:()解析:(1)错误:proc(int k) 正确:double proc

7、int k) (2)错误:return s 正确:return s; 解析 由主函数中的函数调用以及函数 proc()中的 return 语句可知,函数 proc()的返回值类型为 double。因此,“proc(int k)”应改为“double proc(int k)”。根据 C 语言中的语法规则,每一条语句都必须以分号结束。因此,应在语句“return s”后加上分号。三、程序设计题(总题数:1,分数:30.00)3.请编写一个函数,用来删除字符串中的所有空格。 例如,输入 abc de f gh,则输出为 abcdefgh。 注意:部分源程序给出如下。 请勿改动 main()函数和其

8、他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includectype.h #includeconio.h #includestdiib.h void proc(char*str) void main() char str81; system(“CLS“); printf(“Input a string: “); gets(str); puts(str); proc(str); printf(“*str: %s/n“, str); (分数:30.00)_正确答案:()解析:int proc(char*str) int i, j=0; for(i=0; stri!=“/0“; i+) /从下标为 0 开始判断 if(stri!=“) /当其不为空格时,把其放到 str 数组中 strj+=stri; strj=“/0“; /最后用“/0“作为结束标志 解析 根据题目中要求删除字符串中所有的空格,需要检查字符串中的每一个字符。将不是空格的字符放入原来的字符串中,形成新的字符串。在新的字符串的末尾加上结束符。

展开阅读全文
相关资源
猜你喜欢
  • BS 2000-107-1993 Methods of test for petroleum and its products - Determination of sulfur - Lamp combustion method《石油及其制品的试验方法 硫的测定 灯燃法》.pdf BS 2000-107-1993 Methods of test for petroleum and its products - Determination of sulfur - Lamp combustion method《石油及其制品的试验方法 硫的测定 灯燃法》.pdf
  • BS 2000-112-2005+A1-2014 Methods of test for petroleum and its products Determination of corrosiveness to copper of lubricating grease Copper strip method《石油及其制品的试验方法 润滑脂对铜的侵蚀作用测定 .pdf BS 2000-112-2005+A1-2014 Methods of test for petroleum and its products Determination of corrosiveness to copper of lubricating grease Copper strip method《石油及其制品的试验方法 润滑脂对铜的侵蚀作用测定 .pdf
  • BS 2000-12-1993 Methods of test for petroleum and its products - Determination of specific energy《石油和石油产品的试验方法 能量比耗的测定》.pdf BS 2000-12-1993 Methods of test for petroleum and its products - Determination of specific energy《石油和石油产品的试验方法 能量比耗的测定》.pdf
  • BS 2000-121-2005+A1-2014 Methods of test for petroleum and its products Determination of oil separation from lubricating grease Pressure filtration method《石油及其制品的试验方法 从润滑脂中分离油的测定 压.pdf BS 2000-121-2005+A1-2014 Methods of test for petroleum and its products Determination of oil separation from lubricating grease Pressure filtration method《石油及其制品的试验方法 从润滑脂中分离油的测定 压.pdf
  • BS 2000-129-2003 Methods of test for petroleum and its products - Part 129 Determination of bromine number - Colour indicator titration method (Identical with IP 129 2003)《石油及其产品的试.pdf BS 2000-129-2003 Methods of test for petroleum and its products - Part 129 Determination of bromine number - Colour indicator titration method (Identical with IP 129 2003)《石油及其产品的试.pdf
  • BS 2000-13-1994 Methods of test for petroleum and its products - Petroleum products - Determination of carbon residue - Conradson method《石油及其产品的试验方法 石油产品 碳渣的测定 康拉逊法》.pdf BS 2000-13-1994 Methods of test for petroleum and its products - Petroleum products - Determination of carbon residue - Conradson method《石油及其产品的试验方法 石油产品 碳渣的测定 康拉逊法》.pdf
  • BS 2000-130-1998 Methods of test for petroleum and its products - Petroleum products - Determination of bromine number of distillates and aliphatic olefins - Electrometric method《石.pdf BS 2000-130-1998 Methods of test for petroleum and its products - Petroleum products - Determination of bromine number of distillates and aliphatic olefins - Electrometric method《石.pdf
  • BS 2000-132-1996 Methods of test for petroleum and its products - Petroleum products - Lubricating grease - Determination of dropping point《石油和石油产品试验方法 石油产品 第132部分 润滑脂 滴点测定》.pdf BS 2000-132-1996 Methods of test for petroleum and its products - Petroleum products - Lubricating grease - Determination of dropping point《石油和石油产品试验方法 石油产品 第132部分 润滑脂 滴点测定》.pdf
  • BS 2000-133-1993 Methods of test for petroleum and its products - Determination of drop melting point of wax and petrolatum《石油和石油产品的试验方法 石蜡和石蜡油滴熔点的测定》.pdf BS 2000-133-1993 Methods of test for petroleum and its products - Determination of drop melting point of wax and petrolatum《石油和石油产品的试验方法 石蜡和石蜡油滴熔点的测定》.pdf
  • 相关搜索
    资源标签

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

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