【计算机类职业资格】二级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 型变量,用于循环的计数变量为整数,所以必须强制转换。最后返回所求出的平方根。

展开阅读全文
相关资源
猜你喜欢
  • NASA NACA-ACR-5D28-1945 An additional investigation of the high-speed lateral-control characteristics of spoilers《对扰流板高速横向操纵特性的附加研究》.pdf NASA NACA-ACR-5D28-1945 An additional investigation of the high-speed lateral-control characteristics of spoilers《对扰流板高速横向操纵特性的附加研究》.pdf
  • NASA NACA-ACR-L4D12-1944 Wind-tunnel investigation of control-surface characteristics XVII - beveled-trailing-edge flaps of 0 20 0 30 and 0 40 airfoil chord on an NACA 0009 airfoil.pdf NASA NACA-ACR-L4D12-1944 Wind-tunnel investigation of control-surface characteristics XVII - beveled-trailing-edge flaps of 0 20 0 30 and 0 40 airfoil chord on an NACA 0009 airfoil.pdf
  • NASA NACA-ACR-L5F27-1945 Two-dimensional wind-tunnel investigation of 0 20-airfoil-chord plain ailerons of different contour on an NACA 65(sub 1)-210 airfoil section《对NACA65(下标1)-2.pdf NASA NACA-ACR-L5F27-1945 Two-dimensional wind-tunnel investigation of 0 20-airfoil-chord plain ailerons of different contour on an NACA 65(sub 1)-210 airfoil section《对NACA65(下标1)-2.pdf
  • NASA NACA-ACR-L5G31-1945 A simple method for estimating terminal velocity including effect of compressibility on drag《包括压缩性对阻力影响终极速度的一个简单方法》.pdf NASA NACA-ACR-L5G31-1945 A simple method for estimating terminal velocity including effect of compressibility on drag《包括压缩性对阻力影响终极速度的一个简单方法》.pdf
  • NASA NACA-ACR-L5H08-1945 Supersonic-tunnel tests of projectiles in Germany and Italy《德国和意大利投射物的超音速风洞试验》.pdf NASA NACA-ACR-L5H08-1945 Supersonic-tunnel tests of projectiles in Germany and Italy《德国和意大利投射物的超音速风洞试验》.pdf
  • NASA NACA-ACR-L6C13-1946 Field of Flow About a Jet and Effect of Jets on Stability of Jet-Propelled Airplanes《关于喷气式飞机和喷气式飞机对喷气推进式飞机稳定性影响的流场》.pdf NASA NACA-ACR-L6C13-1946 Field of Flow About a Jet and Effect of Jets on Stability of Jet-Propelled Airplanes《关于喷气式飞机和喷气式飞机对喷气推进式飞机稳定性影响的流场》.pdf
  • NASA NACA-ARR-3E25-1943 Full-scale tunnel investigation of the pressure distribution over the tail of the P-47B airplane《P-47B飞机尾翼上压力分布的全面风洞研究》.pdf NASA NACA-ARR-3E25-1943 Full-scale tunnel investigation of the pressure distribution over the tail of the P-47B airplane《P-47B飞机尾翼上压力分布的全面风洞研究》.pdf
  • NASA NACA-ARR-3F23-1943 Wind-tunnel investigation of effect of yaw on lateral-stability characteristics V  symmetrically tapered wing with a circular fuselage having a horizontal a.pdf NASA NACA-ARR-3F23-1943 Wind-tunnel investigation of effect of yaw on lateral-stability characteristics V symmetrically tapered wing with a circular fuselage having a horizontal a.pdf
  • NASA NACA-ARR-3F28-1943 Experimental determination of the yawing moment due to yawing contributed by the wing fuselage and vertical tail of a midwing airplane model《由中置翼飞机模型机翼 机身和垂.pdf NASA NACA-ARR-3F28-1943 Experimental determination of the yawing moment due to yawing contributed by the wing fuselage and vertical tail of a midwing airplane model《由中置翼飞机模型机翼 机身和垂.pdf
  • 相关搜索
    资源标签

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

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