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

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

1、二级 C语言机试-272 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.下列给定程序中,函数 fun的功能是:有 NN矩阵,以主对角线为对称线,对称元素相加并将结果存放在左下三角元素中,右上三角元素置为 O。例如,若 N=3,有下列矩阵:1 2 34 5 67 8 9计算后结果为:1 0 06 5 010 14 9请在下划线处填人正确的内容并把下划线删除,使程序得出正确的结果。注意:部分源程序给出如下。不得增行或删行,也不得更改程序的结构!试题程序:#includescdio.h#define N 4/*found*/void fun(

2、int(*t) (1) )int i,j;for(i=l;iN;i+)for(j=0;ji=j+)/*found*/(2) =tij+tji;/*found*/(3) =0;main()int tN=21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10,i,j;printf(“/nThe original array:/n“);for(i=0;iN;i+)for(j=0;jN;j+)printf(“%2d“,tij;printf(“/n“);fun(t);printf(“/nThe result is:/n“);for(i=0;iN;i+)for(j=

3、0;jN;j+)printf(“%2d“,tij)=printf(“/n“);(分数:30.00)_二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun的功能是:计算函数 F(x,y,z)=(x+y)/(x-y)+(z+y)/(z-y)的值。其中 x和y的值不相等,Z 和 y的值不相等。例如,当 X的值为 9,y 的值为 11,z 的值为 15时,函数值为-350。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includescdlib.h#includestdio.h#includemath

4、h/*found*/#define FU(m,n)(m/n)float fun(float a,float b,float c)float value;value=FU(a+b,a-b)+FU(c+b,c-b);/*found*/retum(Value);void main()float x,y,z,sum;printf(“Input x y z:“);scanf(“%f%f%fprintf(“x=%f,y=%f,z=%f/n“,x,y,z);if(x=y|y=z)(printf(“Data error!/n“);exit(0);)sum=fun(x,Y,z);printf(“The res

5、ult is:%5.2f/n“,sum);(分数:30.00)_三、程序设计题(总题数:1,分数:40.00)3.规定输入的字符串中只包含字母和*号。编写函数 fun,其功能是:将字符串中的前导*号全部删除,中间和尾部的*号不删除。例如,字符串中的内容为“*A*BC*DEF*G*”,删除后,字符串中的内容应当是“A*BC*DEF*G*”。编写函数时,不得使用 C语言提供的字符串函数。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序:#includestdio.h#includeconio.hvoid fun(ch

6、ar*a)void main()char s81;printf(“Enter a string:/n“);gets(s);fun(s);printf(“The string after deleted:/n“);puts(s);(分数:40.00)_二级 C语言机试-272 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.下列给定程序中,函数 fun的功能是:有 NN矩阵,以主对角线为对称线,对称元素相加并将结果存放在左下三角元素中,右上三角元素置为 O。例如,若 N=3,有下列矩阵:1 2 34 5 67 8 9计算后结果为:1 0 06

7、 5 010 14 9请在下划线处填人正确的内容并把下划线删除,使程序得出正确的结果。注意:部分源程序给出如下。不得增行或删行,也不得更改程序的结构!试题程序:#includescdio.h#define N 4/*found*/void fun(int(*t) (1) )int i,j;for(i=l;iN;i+)for(j=0;ji=j+)/*found*/(2) =tij+tji;/*found*/(3) =0;main()int tN=21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10,i,j;printf(“/nThe original a

8、rray:/n“);for(i=0;iN;i+)for(j=0;jN;j+)printf(“%2d“,tij;printf(“/n“);fun(t);printf(“/nThe result is:/n“);for(i=0;iN;i+)for(j=0;jN;j+)printf(“%2d“,tij)=printf(“/n“);(分数:30.00)_正确答案:(N (2)tij (3)tji)解析:解析 本题关键字有:有参函数定义;NN 矩阵左下角和右上角元素的表示。微分析填空 1:主函数中将二维数组传给 fun函数,所以形参类型为指针数组。填空 2:对称元素相加的和存放在左下三角元素中,所以填入

9、 tji。填空 3:右上三角元素置 O,应填入 tji。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun的功能是:计算函数 F(x,y,z)=(x+y)/(x-y)+(z+y)/(z-y)的值。其中 x和y的值不相等,Z 和 y的值不相等。例如,当 X的值为 9,y 的值为 11,z 的值为 15时,函数值为-350。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includescdlib.h#includestdio.h#includemath.h/*found*/#define FU(

10、m,n)(m/n)float fun(float a,float b,float c)float value;value=FU(a+b,a-b)+FU(c+b,c-b);/*found*/retum(Value);void main()float x,y,z,sum;printf(“Input x y z:“);scanf(“%f%f%fprintf(“x=%f,y=%f,z=%f/n“,x,y,z);if(x=y|y=z)(printf(“Data error!/n“);exit(0);)sum=fun(x,Y,z);printf(“The result is:%5.2f/n“,sum);(

11、分数:30.00)_正确答案:(#define FU(m,n)(m)/(n)(2)return(value);)解析:解析 本题关键字有:宏定义;函数返回值。微分析(1)宏定义格式为“#define 标识符字符串”,FU(m,n)为标识符,(m/n)为字符串,其中 m、n 均为表达式,且先计算表达式,所以表达式加小括号。(2)C语言区分大小写,value 与 Value为不同的变量。三、程序设计题(总题数:1,分数:40.00)3.规定输入的字符串中只包含字母和*号。编写函数 fun,其功能是:将字符串中的前导*号全部删除,中间和尾部的*号不删除。例如,字符串中的内容为“*A*BC*DEF*G

12、删除后,字符串中的内容应当是“A*BC*DEF*G*”。编写函数时,不得使用 C语言提供的字符串函数。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序:#includestdio.h#includeconio.hvoid fun(char*a)void main()char s81;printf(“Enter a string:/n“);gets(s);fun(s);printf(“The string after deleted:/n“);puts(s);(分数:40.00)_正确答案:(void fun (char*a)char*p=a;while(*p=*)p+/*指针 p指向字符串第一个字母*/for(;*p!=/0;p+,a+)*a=*p;/*从第一个字母开始的字符都放入指针 a所指的字符串中*/*a=/0;/*在字符串最后加上字符串结束标识符*/)解析:解析 本题关键字有:字符串操作;字符串结束标识符/0/。微分析删除字符串指定字符可采用保留不删除字符的方法,通过循环将保留的字符进行保存,也可用下面程序实现。#includestring.hvoid fun(char*a) char*p=a;while(*p=*)p+;strcpy(a,p);

展开阅读全文
相关资源
猜你喜欢
  • ISO IEC 14568-1997 Information technology - DXL Diagram eXchange Language for tree-structured charts《信息技术 DXL 树结构化图形的图交换语言》.pdf ISO IEC 14568-1997 Information technology - DXL Diagram eXchange Language for tree-structured charts《信息技术 DXL 树结构化图形的图交换语言》.pdf
  • ISO IEC 14575-2000 Information Technology - Microprocessor Systems - Heterogeneous InterConnect (HIC) (Low-Cost Low-Latency Scalable Serial Interconnect for Par.pdf ISO IEC 14575-2000 Information Technology - Microprocessor Systems - Heterogeneous InterConnect (HIC) (Low-Cost Low-Latency Scalable Serial Interconnect for Par.pdf
  • ISO IEC 14576-1999 Information technology - Synchronous split transfer type system bus (Stbus) - Logical layer《信息技术 同步分离传送类型总线(ST总线) 逻辑层》.pdf ISO IEC 14576-1999 Information technology - Synchronous split transfer type system bus (Stbus) - Logical layer《信息技术 同步分离传送类型总线(ST总线) 逻辑层》.pdf
  • ISO IEC 14709-2 AMD 1-2005 Information technology - Configuration of customer premises cabling (CPC) for applications - Part 2 Integrated services digital netwo.pdf ISO IEC 14709-2 AMD 1-2005 Information technology - Configuration of customer premises cabling (CPC) for applications - Part 2 Integrated services digital netwo.pdf
  • ISO IEC 14754-1999 Information technology - Pen-based interfaces - Common gestures for text editing with pen-based systems《信息技术 基于笔的界面 用基于笔的系统编辑文本的通用光笔指令》.pdf ISO IEC 14754-1999 Information technology - Pen-based interfaces - Common gestures for text editing with pen-based systems《信息技术 基于笔的界面 用基于笔的系统编辑文本的通用光笔指令》.pdf
  • ISO IEC 14755-1997 Information technology - Input methods to enter characters from the repertoire of ISO IEC 10646 with a keyboard or other input devices《信息技术 用.pdf ISO IEC 14755-1997 Information technology - Input methods to enter characters from the repertoire of ISO IEC 10646 with a keyboard or other input devices《信息技术 用.pdf
  • ISO IEC 14756-1999 Information technology - Measurement and rating of performance of computer-based software systems《信息技术 以计算机为基础的软件系统性能的测量和评定》.pdf ISO IEC 14756-1999 Information technology - Measurement and rating of performance of computer-based software systems《信息技术 以计算机为基础的软件系统性能的测量和评定》.pdf
  • ISO IEC 14762-2009 Information technology - Functional safety requirements for Home and Building Electronic Systems (HBES)《信息技术 家用和建筑物电子系统(HBES)用功能安全要求》.pdf ISO IEC 14762-2009 Information technology - Functional safety requirements for Home and Building Electronic Systems (HBES)《信息技术 家用和建筑物电子系统(HBES)用功能安全要求》.pdf
  • ISO IEC 14833-1996 Information technology - Data interchange on 12 7 mm 128-track magnetic tape cartridges - DLT 3 format《信息技术 在12 7mm宽、128道盒式磁带上的数据交换 DLT3格式》.pdf ISO IEC 14833-1996 Information technology - Data interchange on 12 7 mm 128-track magnetic tape cartridges - DLT 3 format《信息技术 在12 7mm宽、128道盒式磁带上的数据交换 DLT3格式》.pdf
  • 相关搜索

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

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