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

上传人:roleaisle130 文档编号:1325319 上传时间:2019-10-17 格式:DOC 页数:6 大小:34KB
下载 相关 举报
【计算机类职业资格】二级C语言-375 (1)及答案解析.doc_第1页
第1页 / 共6页
【计算机类职业资格】二级C语言-375 (1)及答案解析.doc_第2页
第2页 / 共6页
【计算机类职业资格】二级C语言-375 (1)及答案解析.doc_第3页
第3页 / 共6页
【计算机类职业资格】二级C语言-375 (1)及答案解析.doc_第4页
第4页 / 共6页
【计算机类职业资格】二级C语言-375 (1)及答案解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、二级 C 语言-375 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:从字符串 str 中取出所有数字字符,并分别计数,然后把结果保存在数组 tt 中并输出,把其他字符保存在 tt10中。 例如,当 str1=“00237481367539dfji”时,结果为 0:21:12:13:34:15:16:17:28:19:1 other charactor:4 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。 试题程序: #

2、includestdlib.h #includestdio.h #includeconio.h void main() int i,tt11; char*str=“00237481367539dfji“; char*p=str; syslem(“CLS“); printf(“*the origial data*/n“); puts(str); for(i=0;i11;i+) tti=0; while(*p) switch( 1) case“0“:tt0+;break; case“1“;tt1+;break; case“2“:tt2+;break; case“3“:tt3+;break; cas

3、e“4“:tt4+;break; case“5“:tt5+;break; case“6“:tt6+;break; case“7“:tt7+;break; case“8“:tt8+;break; case“9“:tt9+;break; 2 3 printf(“*the result*/n“); for(i=0;i10;i+) printf(“/n%d:%d“,i,tti); printf(“/nother charactor:%d“,tti); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:将 m(1m10)个字符串反着连接起来

4、组成一个新串,放入pt 所指字符串中,例如,把“ab、cd、efg”3 个字符串反着串连起来,结果是 efgcdab。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或者删行,也不得改变程序的结构! 试题程序: #includestdlib.h #includeconio.h #includestring.h #includestdio.h void proc(char str10,int m,char*pt) int k,q,i,j=0; /*found* for(k=m;k0;k-) q=strlen(strk); j+=q; for(i=0;iq

5、i+) pti=strki; pt+=q; pt0=0; /*found* pt=j; void main() int m,h; char str1010,p120; system(“CLS“); printf(“/nPlease enter m:“); seanf(“%d“, printf(“/nPlease enter%d string:/n“,m); gets(str0); for(h=0;hm;h+) gets(strh); proc(str,m,p); printf(“/nThe result is:%s/n“,p); (分数:30.00)三、程序设计题(总题数:1,分数:40.0

6、0)3.请编写函数 proc(),该函数的功能是:将 M 行 N 列的二维数组中的数据,按行的顺序依次放到一维数组中,一维数组中数据的个数存放在形参 n 所指的存储单元中。 例如,若二维数组中的数据为: 13 23 33 43 14 24 34 44 15 25 35 45 则一维数组中的内容应该是 13 23 33 43 14 24 34 44 15 25 35 45。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h void proc(int(*s)10,int

7、b,int*n,int mm,int nn) void main() int arr1010=33,33,33,33,44,44,44,44,55,55,55,55,i,j; int a100=0,n=0; printf(“The matrix:/n“); for(i=0;i3;i+) for(j=0;j4;j+) printf(“%3d“,arrij); printf(“/n“); proc(arr,a, printf(“The a array:/n“); for(i=0;in;i+) printf(“%3d“,ai); printf(“/n/n“); (分数:40.00)_二级 C 语言

8、375 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:从字符串 str 中取出所有数字字符,并分别计数,然后把结果保存在数组 tt 中并输出,把其他字符保存在 tt10中。 例如,当 str1=“00237481367539dfji”时,结果为 0:21:12:13:34:15:16:17:28:19:1 other charactor:4 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。 试题程序: #includes

9、tdlib.h #includestdio.h #includeconio.h void main() int i,tt11; char*str=“00237481367539dfji“; char*p=str; syslem(“CLS“); printf(“*the origial data*/n“); puts(str); for(i=0;i11;i+) tti=0; while(*p) switch( 1) case“0“:tt0+;break; case“1“;tt1+;break; case“2“:tt2+;break; case“3“:tt3+;break; case“4“:tt4

10、break; case“5“:tt5+;break; case“6“:tt6+;break; case“7“:tt7+;break; case“8“:tt8+;break; case“9“:tt9+;break; 2 3 printf(“*the result*/n“); for(i=0;i10;i+) printf(“/n%d:%d“,i,tti); printf(“/nother charactor:%d“,tti); (分数:30.00)解析:*p default:tt10+; p+;解析 由整个 switch 语句可知,该语句的功能为判断字符串 str 中每一个字符,因此,第一处填

11、p”;按照题目中要求,将所有非数字字符放在 tt10中,因此,第二处填“default:tt10+;”;指针变量 p 指向字符串 str 中每一个字符,每一次循环时,p 向后移动一个位置,因此,第三处填“p+;”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:将 m(1m10)个字符串反着连接起来,组成一个新串,放入pt 所指字符串中,例如,把“ab、cd、efg”3 个字符串反着串连起来,结果是 efgcdab。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或者删行,也不得改变程序的结构! 试题程序

12、 #includestdlib.h #includeconio.h #includestring.h #includestdio.h void proc(char str10,int m,char*pt) int k,q,i,j=0; /*found* for(k=m;k0;k-) q=strlen(strk); j+=q; for(i=0;iq;i+) pti=strki; pt+=q; pt0=0; /*found* pt=j; void main() int m,h; char str1010,p120; system(“CLS“); printf(“/nPlease enter m:

13、); seanf(“%d“, printf(“/nPlease enter%d string:/n“,m); gets(str0); for(h=0;hm;h+) gets(strh); proc(str,m,p); printf(“/nThe result is:%s/n“,p); (分数:30.00)解析:错误:for(k=m;k0;k-) 正确:for(k=m-1;k=0;k-) 错误:pt=j; 正确:pt-=j; 解析 由函数 proc()可知,变量 k 为二维数组 str 的行下标,其值为 0m-1。因此,“for(k=m;k0;k-)”应改为“for(k=m-1;k=0;k-)

14、每执行完一次循环后,应让 pt 返回到字符串的首地址,因此把“pt=j;”改为“pt-=j;”。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 proc(),该函数的功能是:将 M 行 N 列的二维数组中的数据,按行的顺序依次放到一维数组中,一维数组中数据的个数存放在形参 n 所指的存储单元中。 例如,若二维数组中的数据为: 13 23 33 43 14 24 34 44 15 25 35 45 则一维数组中的内容应该是 13 23 33 43 14 24 34 44 15 25 35 45。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在

15、函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h void proc(int(*s)10,int*b,int*n,int mm,int nn) void main() int arr1010=33,33,33,33,44,44,44,44,55,55,55,55,i,j; int a100=0,n=0; printf(“The matrix:/n“); for(i=0;i3;i+) for(j=0;j4;j+) printf(“%3d“,arrij); printf(“/n“); proc(arr,a, printf(“The a array:/n

16、); for(i=0;in;i+) printf(“%3d“,ai); printf(“/n/n“); (分数:40.00)_正确答案:()解析:void proc(int(*s)10,int*b,int*n,int mm,int nn) int i,j,k=0; for(i=0;imm;i+)/i 是表示其行的下标 for(j=0;jnn;j+) /j 是表示其列的下标 bk+=s00;/把其放到 b 的一维数组中 *n=k; /把 b 数组的长度通过形参 n 传回到主函数中 解析 要将 M 行 N 列的二维数组中的数据,按行的顺序依次放到一维数组中,可以首先通过行循环,然后列循环取出二维数组中的每一个元素,并将其放入一维数组中,最后将一维数组的长度通过形参返回到主函数当中。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO 2597-2-2015 Iron ores Determination of total iron content Titrimetric methods after titanium(III) chloride reduction《铁矿石 总铁含量的测定 钛(III)氯化物还原后的滴定方法》.pdf BS ISO 2597-2-2015 Iron ores Determination of total iron content Titrimetric methods after titanium(III) chloride reduction《铁矿石 总铁含量的测定 钛(III)氯化物还原后的滴定方法》.pdf
  • BS ISO 25981-2008 Road vehicles - Connectors for the electrical connection of towing and towed vehicles - Connectors for electronically monitored charging systems with 12 V or 24 V.pdf BS ISO 25981-2008 Road vehicles - Connectors for the electrical connection of towing and towed vehicles - Connectors for electronically monitored charging systems with 12 V or 24 V.pdf
  • BS ISO 2599-2003 Iron ores - Determination of phosphorus content - Titrimetric method《铁矿石 磷含量的测定 滴定法》.pdf BS ISO 2599-2003 Iron ores - Determination of phosphorus content - Titrimetric method《铁矿石 磷含量的测定 滴定法》.pdf
  • BS ISO 26000-2010 Guidance on social responsibility《社会责任导则》.pdf BS ISO 26000-2010 Guidance on social responsibility《社会责任导则》.pdf
  • BS ISO 26021-1-2008 Road vehicles - End-of-life activation of on-board pyrotechnic devices - General information and use case definitions《道路车辆 车载打火装置报废期的激活 通用信息和使用状态定义》.pdf BS ISO 26021-1-2008 Road vehicles - End-of-life activation of on-board pyrotechnic devices - General information and use case definitions《道路车辆 车载打火装置报废期的激活 通用信息和使用状态定义》.pdf
  • BS ISO 26021-2-2008 Road vehicles - End of-life activation of on-board pyrotechnic devices - Communication requirements《道路车辆 车载打火装置报废期的激活作用 通信要求》.pdf BS ISO 26021-2-2008 Road vehicles - End of-life activation of on-board pyrotechnic devices - Communication requirements《道路车辆 车载打火装置报废期的激活作用 通信要求》.pdf
  • BS ISO 26021-3-2009 Road vehicles - End-of-life activation of on-board pyrotechnic devices - Tool requirements《道路车辆 车载点火装置的报废期激活 工具要求》.pdf BS ISO 26021-3-2009 Road vehicles - End-of-life activation of on-board pyrotechnic devices - Tool requirements《道路车辆 车载点火装置的报废期激活 工具要求》.pdf
  • BS ISO 26021-4-2009 Road vehicles - End-of-life activation of on-board pyrotechnic devices - Additional communication line with bidirectional communication《道路车辆 车载点火装置的报废期激活 具备双向通信.pdf BS ISO 26021-4-2009 Road vehicles - End-of-life activation of on-board pyrotechnic devices - Additional communication line with bidirectional communication《道路车辆 车载点火装置的报废期激活 具备双向通信.pdf
  • BS ISO 26021-5-2009 Road vehicles - End-of-life activation of on-board pyrotechnic devices - Additional communication line with pulse width modulated signal《道路车辆 车载点火装置的报废期激活 承载脉冲宽.pdf BS ISO 26021-5-2009 Road vehicles - End-of-life activation of on-board pyrotechnic devices - Additional communication line with pulse width modulated signal《道路车辆 车载点火装置的报废期激活 承载脉冲宽.pdf
  • 相关搜索

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

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