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

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

1、二级 C 语言-227 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.数组 xxM保存着一组 3 位数的无符号正整数,其元素的个数通过变量 m 传入函数 proc()。请补充函数proc(),该函数的功能是:从数组 xx 中找出十位和百位的数字相等的所有无符号整数,结果保存在数组yy 中,其个数由函数 proc()返回。 例如,当 xx8=234 339 666 850 220 448 528 440时,bb5=339 666 220 448 440。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函

2、数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #includestdlib.h #includeconio.b #define M 1000 int proc(int xx,int bb,int m) int i,n=0; int a,b; for(i=0;im;i+) a= 1; b=xxi/100; if(a=b) 2; return 3; void main() int xx8=234,339,666,850,220,448,528,140; int yyM; int m=0,n=0,i=0; m=8; system(“CLS“);

3、printf(“*original data*/n“); for(i=0;im;j+) printf(“%u“,xxi); printf(“/n/n/n“); n=proc(xx,yy,m); printf(“/nyy=“); for(i=0:in;i+) printf(“%u“,yyj); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:将长整型数中为偶数的数依次取出,构成一个新数放在 t 中。高位仍在高位,低位仍在低位。例如,当 s 中的数为 87653142 时,t 中的数为 864.2。 请修改程序中的错误,使它能得出正

4、确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h void proc(long s,long*t) int d; long s1=1; *t=0; while(s0) d=s%10; /*found* if(d%2=0) *t=d*s1+*t; s1*=10; /*found* s/=10; void main() long s,t; system(“CLS“); printf(“/nPlease enter s:“);scanf (“%1d“, p

5、roc(s, printf(“The result is:%1d/n“,t); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.程序定义了 MM 的二维数组,并在主函数中自动赋值。请编写函数 proc(int aM,int n),该函数的功能是使数组左下半三角元素中的值加上 n。例如,a 数组中的值为: 若 n 的值为 2,则返回主程序后 a 数组中的值为: (分数:40.00)_二级 C 语言-227 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.数组 xxM保存着一组 3 位数的无符号正整数,其元素的个数通过变量

6、 m 传入函数 proc()。请补充函数proc(),该函数的功能是:从数组 xx 中找出十位和百位的数字相等的所有无符号整数,结果保存在数组yy 中,其个数由函数 proc()返回。 例如,当 xx8=234 339 666 850 220 448 528 440时,bb5=339 666 220 448 440。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #includestdlib.h #includeconio.b #define M 1000

7、int proc(int xx,int bb,int m) int i,n=0; int a,b; for(i=0;im;i+) a= 1; b=xxi/100; if(a=b) 2; return 3; void main() int xx8=234,339,666,850,220,448,528,140; int yyM; int m=0,n=0,i=0; m=8; system(“CLS“); printf(“*original data*/n“); for(i=0;im;j+) printf(“%u“,xxi); printf(“/n/n/n“); n=proc(xx,yy,m); p

8、rintf(“/nyy=“); for(i=0:in;i+) printf(“%u“,yyj); (分数:30.00)解析:(xxi/10)%10 bbn+=xxi n解析 要找出数组 xx 中十位和百位数字相等的所有整数,首先要得到数组中每一个整数的十位和百位数字,因此,第一处填“(xxi/10)%10”;如果十位和百位数字相等,则将该整数放在数组 bb 中,因此,第二处填“bbn+=xxi”;符合条件的整数个数放在变量 n中,返回给主函数,因此,第三处填“n”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:将长整型数中为偶数的数依次取出,构成

9、一个新数放在 t 中。高位仍在高位,低位仍在低位。例如,当 s 中的数为 87653142 时,t 中的数为 864.2。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h void proc(long s,long*t) int d; long s1=1; *t=0; while(s0) d=s%10; /*found* if(d%2=0) *t=d*s1+*t; s1*=10; /*found* s/=10; vo

10、id main() long s,t; system(“CLS“); printf(“/nPlease enter s:“);scanf (“%1d“, proc(s, printf(“The result is:%1d/n“,t); (分数:30.00)解析:错误:if(d%2=0) 正确:if(d%2=0) 错误:s/=10; 正确:s/=10; 解析 将长整型数中每一位上为偶数的数依次取出,构成一个新数。需要检查长整数型的每一位是否为偶数,因此,“if(d%2=0)”应改为“if(d%2=0)”;在 C 语言中,除号的写法为/,因此“s/=10;”应改为“s/=10;”。三、程序设计题(

11、总题数:1,分数:40.00)3.程序定义了 MM 的二维数组,并在主函数中自动赋值。请编写函数 proc(int aM,int n),该函数的功能是使数组左下半三角元素中的值加上 n。例如,a 数组中的值为: 若 n 的值为 2,则返回主程序后 a 数组中的值为: (分数:40.00)_正确答案:()解析:void proc(int aM,int n) int i,j; for(i=0;iM;i+) /i 是为了控制行的下标 for(j=0;j=i;j+) /j 是控制左下半三角的列下标,直到行列下标相同 aij=aij+n; /此语句的作用是让其与 n 相加 解析 使数组左下半三角元素中的值加上 n,首先要找出数组中下半三角元素。数组中下半三角元素的特点是,其列下标小于等于行下标。根据这个特点找出所有的下半三角元素再加上 n 放在原来的位置上。

展开阅读全文
相关资源
猜你喜欢
  • EN ISO 2439-2008 en Flexible cellular polymeric materials - Determination of hardness (indentation technique)《软质泡沫聚合材料压陷硬度试验方法(压痕法)》.pdf EN ISO 2439-2008 en Flexible cellular polymeric materials - Determination of hardness (indentation technique)《软质泡沫聚合材料压陷硬度试验方法(压痕法)》.pdf
  • EN ISO 2440-1999 en Flexible and rigid cellular polymeric materials - accelerated ageing tests (Incorporates Amendment A2 2014)《软质和硬质泡沫聚合材料 加速老化试验 包含修改件A1-2010》.pdf EN ISO 2440-1999 en Flexible and rigid cellular polymeric materials - accelerated ageing tests (Incorporates Amendment A2 2014)《软质和硬质泡沫聚合材料 加速老化试验 包含修改件A1-2010》.pdf
  • EN ISO 2450-2008 en Cream - Determination of fat content - Gravimetric method (Reference method)《奶油脂肪含量的测定重量分析法(参照法)》.pdf EN ISO 2450-2008 en Cream - Determination of fat content - Gravimetric method (Reference method)《奶油脂肪含量的测定重量分析法(参照法)》.pdf
  • EN ISO 2495-2000 en Iron Blue Pigments - Specifications and Methods of Test《铁蓝颜料 规范和测试方法》.pdf EN ISO 2495-2000 en Iron Blue Pigments - Specifications and Methods of Test《铁蓝颜料 规范和测试方法》.pdf
  • EN ISO 2503-2009 en Gas welding equipment - Pressure regulators and pressure regulators with flow-metering devices for gas cylinders used in welding cutting and allied processes up.pdf EN ISO 2503-2009 en Gas welding equipment - Pressure regulators and pressure regulators with flow-metering devices for gas cylinders used in welding cutting and allied processes up.pdf
  • EN ISO 2505-2005 en Thermoplastics pipes - Longitudinal reversion - Test method and parameters《热塑性管 纵向回缩的试验方法和参数 (ISO 2505)-2005 -1994[代替 CEN EN 743]》.pdf EN ISO 2505-2005 en Thermoplastics pipes - Longitudinal reversion - Test method and parameters《热塑性管 纵向回缩的试验方法和参数 (ISO 2505)-2005 -1994[代替 CEN EN 743]》.pdf
  • EN ISO 2507-1-2017 en Thermoplastics pipes and fittings - Vicat softening temperature - Part 1 General test method.pdf EN ISO 2507-1-2017 en Thermoplastics pipes and fittings - Vicat softening temperature - Part 1 General test method.pdf
  • EN ISO 2507-3-2017 en Thermoplastics pipes and fittings - Vicat softening temperature - Part 3 Test conditions for acrylonitrile butadiene styrene (ABS) and acrylonitrile styrene a.pdf EN ISO 2507-3-2017 en Thermoplastics pipes and fittings - Vicat softening temperature - Part 3 Test conditions for acrylonitrile butadiene styrene (ABS) and acrylonitrile styrene a.pdf
  • EN ISO 252-2007 en Conveyor belts - Adhesion between constitutive elements - Test methods《输送带 结构元件间的粘附的试验方法[代替 CEN EN ISO 252-1]》.pdf EN ISO 252-2007 en Conveyor belts - Adhesion between constitutive elements - Test methods《输送带 结构元件间的粘附的试验方法[代替 CEN EN ISO 252-1]》.pdf
  • 相关搜索

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

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