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

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

1、二级 C 语言-382 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun()的功能是:把形参 s 所指字符串中下标为奇数的字符右移到下一个奇数位置,最右边被移出字符串的字符绕回放到第一个奇数位置,下标为偶数的字符不动(注:字符串的长度大于等于 2)。 例如,形参 s 所指的字符串为:abcdefgh,执行结果为:ahcbedgf。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 fun()函数的横线上填入所编写的若干表达式或语句。试题程序: #includestdio.h

2、void fun(char*s) int i,n,k; char c; n=0; for(i=0;si!=“/0“;i+) n+; if(n%2=0) k=n- 1; else k=n- 2; c=sk; for(i=k-2;i=1;i=i-2) si+2=si; s1= 3; void main() char s80=“abcdefgh“; printf(“/nThe original string is:%s/n“,s); fun (s); printf(“/nThe result is:%s/n“,s); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序

3、中,函数 fun()的功能是:实现两个变量值的交换,规定不允许增加语句和表达式。 例如,变量 a 中的值原为 8,b 中的值原为 3,程序运行后,a 中的值为 3,b 中的值为 8。 请改正程序中的错误,使它得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includestdlib.h #includeconio.h #includestdio.h int fun(int*x,int y) int t; /*found* t=x;x=y; /*found* return(y); void main() int a=3,b=8; syst

4、em(“CLS“); printf(“%d%d/n“,a,b); b=fun( printf(“%d%d/n“,a,b); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.编写函数 fun(),其功能是:求出 11000 中能被 7 或 11 整除,但不能同时被 7 和 11 整除的所有整数,并将其放在 a 所指的数组中,通过 n 返回这些数的个数。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 fun()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includ

5、estdio.h void fun(int*a,int*n) void main() int aa1000,n,k; system(“CLS“); fun(aa, for(k=0;kn;k+) if(k+1)%10=0) printf(“%5d“,aak); printf(“/n“);/一行写 9 个数 else printf(“%5d“,aak); printf(“/n“); (分数:40.00)_二级 C 语言-382 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun()的功能是:把形参 s 所指字符串中下

6、标为奇数的字符右移到下一个奇数位置,最右边被移出字符串的字符绕回放到第一个奇数位置,下标为偶数的字符不动(注:字符串的长度大于等于 2)。 例如,形参 s 所指的字符串为:abcdefgh,执行结果为:ahcbedgf。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 fun()函数的横线上填入所编写的若干表达式或语句。试题程序: #includestdio.h void fun(char*s) int i,n,k; char c; n=0; for(i=0;si!=“/0“;i+) n+; if(n%2=0) k=n- 1; else k=n- 2; c=

7、sk; for(i=k-2;i=1;i=i-2) si+2=si; s1= 3; void main() char s80=“abcdefgh“; printf(“/nThe original string is:%s/n“,s); fun (s); printf(“/nThe result is:%s/n“,s); (分数:30.00)解析:1 sk或*(s+k) c解析 本程序的作用是将字符串(即字符数组)中奇数位置(下标)的字符循环后移,即最后一个奇数位置的字符移到第一个奇数位置,其他奇数位置字符后移一个位置。第一个 for 循环的作用是求出字符串 s 的长度 n。如果 n 是偶数,字符

8、串下标为奇数的最后一个字符就是前一个字符,k=n-1;如果 n 是奇数,k=n-2。将字符 sk保存到 c 中,通过循环实现减遍历,将下标为奇数的字符都后移 2 位(因为包含偶数,所以后移 2 位,就是后移到下一个奇数位)。最后将最右边被移出字符串的字符放到第一个奇数位置。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:实现两个变量值的交换,规定不允许增加语句和表达式。 例如,变量 a 中的值原为 8,b 中的值原为 3,程序运行后,a 中的值为 3,b 中的值为 8。 请改正程序中的错误,使它得出正确的结果。 注意:不要改动 main()函数,不得

9、增行或删行,也不得更改程序的结构! 试题程序: #includestdlib.h #includeconio.h #includestdio.h int fun(int*x,int y) int t; /*found* t=x;x=y; /*found* return(y); void main() int a=3,b=8; system(“CLS“); printf(“%d%d/n“,a,b); b=fun( printf(“%d%d/n“,a,b); (分数:30.00)解析:错误:t=x;x=y; 正确:t=*x;*x=y; 错误:return(y); 正确:return(t);或 re

10、turn t; 解析 该题考查的是指针型变量的使用和如何通过 return 语句返回函数值。首先应该明确,题目中给出的 x 是指针型函数,所以数据交换时应使用“*x”而不是“x”;t 是一个中间变量,而且由赋值语句“b=fun(8a,b)”可知,返回值将赋给变量 b,而 b 中应存放交换前*x 中的值,所以返回的变量应为 t,而非 y。三、程序设计题(总题数:1,分数:40.00)3.编写函数 fun(),其功能是:求出 11000 中能被 7 或 11 整除,但不能同时被 7 和 11 整除的所有整数,并将其放在 a 所指的数组中,通过 n 返回这些数的个数。 注意:部分源程序给出如下。 请

11、勿改动 main()函数和其他函数中的任何内容,仅在函数 fun()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h void fun(int*a,int*n) void main() int aa1000,n,k; system(“CLS“); fun(aa, for(k=0;kn;k+) if(k+1)%10=0) printf(“%5d“,aak); printf(“/n“);/一行写 9 个数 else printf(“%5d“,aak); printf(“/n“); (分数:40.00)_正

12、确答案:()解析:void fun(int*a,int*n) int i,j=0; for(i=1;i=1000;i+)/求 11000 能被 7 或 11 整除但不能同时被 7 和 11 整除的所有整数,并将其放入数组 a 中 if(i%7=0|i%11=0) *n=j; /传回满足条件的数的个数 解析 根据题意,所写函数要用 for 循环实现对整数 11000 的遍历;通过 if 语句找出能被 7 或 11整除,但不能同时被 7 和 111 整除的所有整数,因为同时被 7 和 11 整除的整数一定能被 77 整除,且不能被 77 整除的数不一定就是能被 7 或 11 整除,可得出表达式“(i%7=0|i%11=0)&i%77!=0”;再按题目要求,将找出来的整数放在 a 所指的数组中,通过 n 返回这些数的个数即可。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO 11903-2008 Tools for pressing - Guide pillar mountings《冲压工具 导柱安装指南》.pdf BS ISO 11903-2008 Tools for pressing - Guide pillar mountings《冲压工具 导柱安装指南》.pdf
  • BS ISO 11907-1-1998 Plastics - Smoke generation - Determination of the corrosivity of fire effluents - Guidance《塑料制品 烟雾生成 灭火废液腐蚀性的测定 第1部分 指南》.pdf BS ISO 11907-1-1998 Plastics - Smoke generation - Determination of the corrosivity of fire effluents - Guidance《塑料制品 烟雾生成 灭火废液腐蚀性的测定 第1部分 指南》.pdf
  • BS ISO 11907-2-1996 Plastics - Smoke generation - Determination of the corrosivity of fire effluents - Static method《塑料制品 烟雾生成 火灾流出物腐蚀性的测定 第2部分 静态法》.pdf BS ISO 11907-2-1996 Plastics - Smoke generation - Determination of the corrosivity of fire effluents - Static method《塑料制品 烟雾生成 火灾流出物腐蚀性的测定 第2部分 静态法》.pdf
  • BS ISO 11907-3-1998 Plastics - Smoke generation - Determination of the corrosivity of fire effluents - Dynamic decomposition method using a travelling furnace《塑料制品 烟雾生成 灭火废液腐蚀性的测定 .pdf BS ISO 11907-3-1998 Plastics - Smoke generation - Determination of the corrosivity of fire effluents - Dynamic decomposition method using a travelling furnace《塑料制品 烟雾生成 灭火废液腐蚀性的测定 .pdf
  • BS ISO 11907-4-1998 Plastics - Smoke generation - Determination of the corrosivity of fire effluents - Dynamic decomposition method using a conical radiant heater《塑料制品 烟雾生成 灭火废液腐蚀性.pdf BS ISO 11907-4-1998 Plastics - Smoke generation - Determination of the corrosivity of fire effluents - Dynamic decomposition method using a conical radiant heater《塑料制品 烟雾生成 灭火废液腐蚀性.pdf
  • BS ISO 11916-1-2013 Soil quality Determination of selected explosives and related compounds Method using high-performance liquid chromatography (HPLC) with ultraviolet detection《土质.pdf BS ISO 11916-1-2013 Soil quality Determination of selected explosives and related compounds Method using high-performance liquid chromatography (HPLC) with ultraviolet detection《土质.pdf
  • BS ISO 11916-2-2013 Soil quality Determination of selected explosives and related compounds Method using gas chromatography (GC) with electron capture detection (ECD) or mass spect.pdf BS ISO 11916-2-2013 Soil quality Determination of selected explosives and related compounds Method using gas chromatography (GC) with electron capture detection (ECD) or mass spect.pdf
  • BS ISO 11922-2-1997 Thermoplastics pipes for the conveyance of fluids - Dimensions and tolerances - Inch-based series《流体传输用热塑管 尺寸和公差 英制系列》.pdf BS ISO 11922-2-1997 Thermoplastics pipes for the conveyance of fluids - Dimensions and tolerances - Inch-based series《流体传输用热塑管 尺寸和公差 英制系列》.pdf
  • BS ISO 11925-3-1998 Reaction to fire tests Ignitability of building products subjected to direct impingement of flame Multi-source test《防火试验的反作用 受火焰直接影响建筑产品的可燃性 多火源试验》.pdf BS ISO 11925-3-1998 Reaction to fire tests Ignitability of building products subjected to direct impingement of flame Multi-source test《防火试验的反作用 受火焰直接影响建筑产品的可燃性 多火源试验》.pdf
  • 相关搜索

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

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