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

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

1、二级 C 语言-336 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:把一个二维字符数组每行字符串中最大的字符复制到字符数组s 中。 例如,如果 arr3=“hoih“, “yufui“, “xgf“,则 str=“oyx“。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h void main() int i=0; cha

2、r*arr3=“hoih“, “yufui“, “xgf“; char*p; char str8; system(“CLS“); 1; for(i=0; i3; i+) stri=*pi; while(*pi) if(stri*pi) stri=*pi; 2; 3; printf(“new string/n“); puts(str); (分数:30.00)二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中,函数 proc()的功能是:先从键盘上输入一个 3 行 3 列的矩阵的各个元素的值,然后输出主对角线元素之积。 请修改函数 proc()中的错误,使它能得出正确的结果。 注意:

3、不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdio.h void proc() int arr33, mul; int i, j; mul=1; printf(“please input an 3*3 array: /n“); for(i=0; i3; i+) /*found* for(i=0; j3; j+) scanf(“%d“, for(i=0; i3; i+) /*found* mul=mul*arrij; printf(“Mul=%d/n“, mul); void main() proc(); (分数:40.00)_三、程序设计

4、题(总题数:1,分数:30.00)3.请编写一个函数 unsigned proc(unsigned u),u 是一个大于 10 的无符号整数,若 u 是 n(5n2)位的整数,则函数求出 u 的后 n-1 位的数作为函数值返回。 例如,u 值为 1234,则函数返回 234;若 u 值为 234,则函数返回 34。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h unsigned proc(unsig

5、ned u) void main() unsigned x; system(“CLS“); printf(“Enter a unsigned integer number: “); scanf(“%u“, printf(“The original data is: %u/n“, x); if(x10) printf(“Data error!“); else printf(“The result: %u/n“, proc(x); (分数:30.00)_二级 C 语言-336 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 mai

6、n()函数,该函数的功能是:把一个二维字符数组每行字符串中最大的字符复制到字符数组s 中。 例如,如果 arr3=“hoih“, “yufui“, “xgf“,则 str=“oyx“。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h void main() int i=0; char*arr3=“hoih“, “yufui“, “xgf“; char*p; char str8; system(“CLS“); 1; for(i=

7、0; i3; i+) stri=*pi; while(*pi) if(stri*pi) stri=*pi; 2; 3; printf(“new string/n“); puts(str); (分数:30.00)解析:p=arr pi+ stri=“/0“解析 由程序可知,变量 p 指向的二维数组的首地址,因此第一处填“p=arr”;要找出二维数组中每一行的最大字符,就要检查每一行的每一个字符,因此第二处填“pi+”;最后要为得到的结果字符串加上结束符,因此第三处填“stri=“/0“”。二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中,函数 proc()的功能是:先从键盘上输入

8、一个 3 行 3 列的矩阵的各个元素的值,然后输出主对角线元素之积。 请修改函数 proc()中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdio.h void proc() int arr33, mul; int i, j; mul=1; printf(“please input an 3*3 array: /n“); for(i=0; i3; i+) /*found* for(i=0; j3; j+) scanf(“%d“, for(i=0; i3; i+) /*found* mul=mul*ar

9、rij; printf(“Mul=%d/n“, mul); void main() proc(); (分数:40.00)_正确答案:()解析:(1)错误:for(i=0; j3; j+) 正确:for(j=0; j3; j+) (2)错误:mul=mul*arrij; 正确:mul=mul*arrii; 解析 由函数 proc()可知,变量 i,j 分别表示二维数组的行和列,从键盘输入二维数组的元素是按行输入的,因此“for(i=0; j3; j+)”应改为“for(j=0; j3; j+)”;二维数组主对角线上元素的两个下标是相等的,因此“mul=mul*arrij;”应改为“mul=mul

10、arrii;”。三、程序设计题(总题数:1,分数:30.00)3.请编写一个函数 unsigned proc(unsigned u),u 是一个大于 10 的无符号整数,若 u 是 n(5n2)位的整数,则函数求出 u 的后 n-1 位的数作为函数值返回。 例如,u 值为 1234,则函数返回 234;若 u 值为 234,则函数返回 34。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h unsi

11、gned proc(unsigned u) void main() unsigned x; system(“CLS“); printf(“Enter a unsigned integer number: “); scanf(“%u“, printf(“The original data is: %u/n“, x); if(x10) printf(“Data error!“); else printf(“The result: %u/n“, proc(x); (分数:30.00)_正确答案:()解析:unsigned proc(unsigned u) if(u=10000) /此时 u 为五位,则返回其后的四位 return u%10000; if(u=1000) /此时 u 为四位,则返回其后的三位 return u%1000; if(u=100) /此时 u 为三位,则返回其后的两位 return u%100; if(u=10) /此时 u 为两位,则返回其后的一位 return u%10; 解析 要返回无符号整数的后 n-1 位,首先要判断无符号整数的位数,然后通过求余来实现。

展开阅读全文
相关资源
猜你喜欢
  • KS K ISO 12027-2012 Textiles-Cotton-fibre stickiness-Detection of sugar by colour reaction《纺织品 原棉的粘着性 通过颜色恒定反应检出糖分》.pdf KS K ISO 12027-2012 Textiles-Cotton-fibre stickiness-Detection of sugar by colour reaction《纺织品 原棉的粘着性 通过颜色恒定反应检出糖分》.pdf
  • KS K ISO 12957-1-2010 Geosynthetics-Determination of friction characteristics-Part 1 Direct shear test《土工合成织物 摩擦特性的测定 第1部分 直接剪切试验》.pdf KS K ISO 12957-1-2010 Geosynthetics-Determination of friction characteristics-Part 1 Direct shear test《土工合成织物 摩擦特性的测定 第1部分 直接剪切试验》.pdf
  • KS K ISO 12957-2-2010 Geosynthetics-Determination of friction characteristics-Part 2:Inclined plane test《土工合成织物 摩擦特性的测定 第2部分 倾斜面试验》.pdf KS K ISO 12957-2-2010 Geosynthetics-Determination of friction characteristics-Part 2:Inclined plane test《土工合成织物 摩擦特性的测定 第2部分 倾斜面试验》.pdf
  • KS K ISO 13426-2-2007 Geotextiles and geotextile-related products-Strength of internal structural junctions-Part 2:Geocomposites《土工织物及其相关产品 内部结构连接强度 第2部分 土工织物复合材料》.pdf KS K ISO 13426-2-2007 Geotextiles and geotextile-related products-Strength of internal structural junctions-Part 2:Geocomposites《土工织物及其相关产品 内部结构连接强度 第2部分 土工织物复合材料》.pdf
  • KS K ISO 13428-2007 Geosynthetics-Determination of the protection efficiency of a geosynthetic against impact damage《土工合成织物 土工合成织物抗冲击损坏的保护效率的测定》.pdf KS K ISO 13428-2007 Geosynthetics-Determination of the protection efficiency of a geosynthetic against impact damage《土工合成织物 土工合成织物抗冲击损坏的保护效率的测定》.pdf
  • KS K ISO 13431-2012 Geotextiles and geotextile-related products-Determination of tensile creep and creep rupture behaviour《土工织物和土工织物相关产品 拉伸蠕变和蠕变断裂的测定》.pdf KS K ISO 13431-2012 Geotextiles and geotextile-related products-Determination of tensile creep and creep rupture behaviour《土工织物和土工织物相关产品 拉伸蠕变和蠕变断裂的测定》.pdf
  • KS K ISO 13437-2007 Geotextiles and geotextile-related products-Method for installing and extracting samples in soil and testing specimens in laboratory《土工织物及其相关制品 装配、土壤中萃取抽样和实验室用试.pdf KS K ISO 13437-2007 Geotextiles and geotextile-related products-Method for installing and extracting samples in soil and testing specimens in laboratory《土工织物及其相关制品 装配、土壤中萃取抽样和实验室用试.pdf
  • KS K ISO 13438-2007 Geotextiles and geotextile-related products-Screening test method for determining the resistance to oxidation《土工织物和土工织物相关产品 测定耐氧化性的筛选试验方法》.pdf KS K ISO 13438-2007 Geotextiles and geotextile-related products-Screening test method for determining the resistance to oxidation《土工织物和土工织物相关产品 测定耐氧化性的筛选试验方法》.pdf
  • KS K ISO 13506-2010 Protective clothing against heat and flame-Test method for complete garments-Prediction of burn injury using an instrumented manikin《防热和防火防护服 完整服装的试验方法 用装备仪器的假人.pdf KS K ISO 13506-2010 Protective clothing against heat and flame-Test method for complete garments-Prediction of burn injury using an instrumented manikin《防热和防火防护服 完整服装的试验方法 用装备仪器的假人.pdf
  • 相关搜索

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

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