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

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

1、二级 C 语言-298 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.函数 fun()的功能是:逆置数组元素中的值。形参 n 给出数组中数据的个数。 例如:若 a 所指数组中的数据依次为:1、2、3、4、5、6、7、8、9,则逆置后依次为:9、8、7、6、5、4、3、2、1。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 fun()函数的横线上填入所编写的若干表达式或语句。试题程序: #includestdio.h void fun(int a, int n) int i, t; for(i=

2、0; i 1; i+) t=ai; ai=an-1- 2; 3=t; void main() int b9=1, 2, 3, 4, 5, 6, 7, 8, 9, i; printf(“/nThe original data: /n“); for(i=0; i9; i+) printf(“%4d“, bi); printf(“/n“); fun(b, 9); printf(“/nThe data after invert: /n“); for(i=0; i9; i+) printf(“%4d“, bi); printf(“/n“); (分数:30.00)二、程序改错题(总题数:1,分数:40.0

3、0)2.下列给定程序中,函数 fun()的功能是:将 tt 所指字符串中的小写字母全部改为对应的大写字母,其他字符不变。 例如,若输入“Ab,cD”,则输出“AB,CD”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includeconio.h #includestdio.h #includestring.h char*fun(char tt) int i; for(i=0; tti; i+) /*found* if(tti=“a“)|(tti=“z“) /*found* tti+=32; return(

4、tt); void main() char tt81; printf(“/nPlease enter a string: “); gets(tt); printf(“/nThe result string is: %s/n“, fun(tt); (分数:40.00)_三、程序设计题(总题数:1,分数:30.00)3.编写函数 fun(),其功能是计算: (分数:30.00)_二级 C 语言-298 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.函数 fun()的功能是:逆置数组元素中的值。形参 n 给出数组中数据的个数。 例如:若

5、a 所指数组中的数据依次为:1、2、3、4、5、6、7、8、9,则逆置后依次为:9、8、7、6、5、4、3、2、1。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 fun()函数的横线上填入所编写的若干表达式或语句。试题程序: #includestdio.h void fun(int a, int n) int i, t; for(i=0; i 1; i+) t=ai; ai=an-1- 2; 3=t; void main() int b9=1, 2, 3, 4, 5, 6, 7, 8, 9, i; printf(“/nThe original data:

6、 /n“); for(i=0; i9; i+) printf(“%4d“, bi); printf(“/n“); fun(b, 9); printf(“/nThe data after invert: /n“); for(i=0; i9; i+) printf(“%4d“, bi); printf(“/n“); (分数:30.00)解析:n/2 i an-i-1解析 fun()函数实现的功能是实现数组的逆置。具体步骤通过参数传递,得到数组指针(即数组名)和数组记录大小的变量 n,通过这两个参数配置 for 循环,遍历数组的中间的元素位置,每次循环都将 i 位置和对应位置结点(i 距离 0 位置

7、等于其距离尾位置的结点)的元素交换,由此实现数组的逆置。二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中,函数 fun()的功能是:将 tt 所指字符串中的小写字母全部改为对应的大写字母,其他字符不变。 例如,若输入“Ab,cD”,则输出“AB,CD”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includeconio.h #includestdio.h #includestring.h char*fun(char tt) int i; for(i=0; tti; i+) /*found

8、 if(tti=“a“)|(tti=“z“) /*found* tti+=32; return(tt); void main() char tt81; printf(“/nPlease enter a string: “); gets(tt); printf(“/nThe result string is: %s/n“, fun(tt); (分数:40.00)_正确答案:()解析:(1)错误:if(tti=“a“)|(tti=“z“) 正确:if(tti=“a“) 正确:tti-=32; 解析 题目要求将小写字母改为对应的大写字母,要判断是否是小写字母,只需判断字母是否在“a“z“,因此应该是“(tti=“a“) double s=0.0; for(i=1; i=m; i+) s=s+log(i); /*计算 s=ln(1)+ln(2)+in(3)+ln(m)*/ return sqrt(s); /*对 s 求平方根并返回*/ 解析 题目要求写出程序实现数学表达式的功能,需要用 for 循环计算累加的结果,调用 sqrt 函数实现求平方根。循环变量的范围是 1m,每次循环部进行一次累加求和。需要特别注意的是,log 函数的形式参数为 double 型变量,用于循环的计数变量为整数,所以必须强制转换。最后返回所求出的平方根。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO 3629-2002 Photography - Processing chemicals - Specifications for potassium metabisulfite《照相 加工处理药液 偏亚硫酸氢钾规范》.pdf BS ISO 3629-2002 Photography - Processing chemicals - Specifications for potassium metabisulfite《照相 加工处理药液 偏亚硫酸氢钾规范》.pdf
  • BS ISO 363-1-2006 Textile machinery and accessories - Flat steel healds with closed end loops - Dimensions of healds manufactured of rolled steel wire《纺织机械和附件 带闭端环式钢制片综 轧钢丝制片综尺寸》.pdf BS ISO 363-1-2006 Textile machinery and accessories - Flat steel healds with closed end loops - Dimensions of healds manufactured of rolled steel wire《纺织机械和附件 带闭端环式钢制片综 轧钢丝制片综尺寸》.pdf
  • BS ISO 363-2-2006 Textile machinery and accessories - Flat steel healds with closed end loops - Dimensions of healds manufactured of hardened strip steel《纺织机械及附件 闭口环式扁钢片综 硬质带钢制成的综片.pdf BS ISO 363-2-2006 Textile machinery and accessories - Flat steel healds with closed end loops - Dimensions of healds manufactured of hardened strip steel《纺织机械及附件 闭口环式扁钢片综 硬质带钢制成的综片.pdf
  • BS ISO 3632-1-2011 Spices Saffron (Crocus sativus L ) Specification《调料 藏红花(番红花) 规范》.pdf BS ISO 3632-1-2011 Spices Saffron (Crocus sativus L ) Specification《调料 藏红花(番红花) 规范》.pdf
  • BS ISO 3632-2-2010 Spices Saffron (Crocus sativus L ) Test methods《香料 藏红花(Crocus sativus L ) 试验方法》.pdf BS ISO 3632-2-2010 Spices Saffron (Crocus sativus L ) Test methods《香料 藏红花(Crocus sativus L ) 试验方法》.pdf
  • BS ISO 3651-3-2017 Determination of resistance to intergranular corrosion of stainless steels Corrosion test for low-Cr ferritic stainless steels《不锈钢抗晶间腐蚀的测定 第3部分 低铬铁素体不锈钢腐蚀试验》.pdf BS ISO 3651-3-2017 Determination of resistance to intergranular corrosion of stainless steels Corrosion test for low-Cr ferritic stainless steels《不锈钢抗晶间腐蚀的测定 第3部分 低铬铁素体不锈钢腐蚀试验》.pdf
  • BS ISO 366-2-2009 Textile machinery and accessories - Reeds - Dimensions and designation of metal reeds with plate baulk《纺织机械和附件 筘 平板梁金属丝扣筘的尺寸规格和标识》.pdf BS ISO 366-2-2009 Textile machinery and accessories - Reeds - Dimensions and designation of metal reeds with plate baulk《纺织机械和附件 筘 平板梁金属丝扣筘的尺寸规格和标识》.pdf
  • BS ISO 366-3-2009 Textile machinery and accessories - Reeds - Dimensions and designation of metal reeds with double-spring baulk《纺织机械与附件 筘 第3部分 双弹性梁金属丝扎筘的尺寸规格和标识》.pdf BS ISO 366-3-2009 Textile machinery and accessories - Reeds - Dimensions and designation of metal reeds with double-spring baulk《纺织机械与附件 筘 第3部分 双弹性梁金属丝扎筘的尺寸规格和标识》.pdf
  • BS ISO 366-4-2005 Textile machinery and accessories - Reeds - Dimensions and designation of plastic-bound metal reeds《纺织机械和附件 钢筘 塑料连接金属钢筘的尺寸和标记》.pdf BS ISO 366-4-2005 Textile machinery and accessories - Reeds - Dimensions and designation of plastic-bound metal reeds《纺织机械和附件 钢筘 塑料连接金属钢筘的尺寸和标记》.pdf
  • 相关搜索
    资源标签

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

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