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

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

1、二级 C 语言机试-113 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)请补充 main 函数,该函数的功能是求方程 ax2+bx+c=0 的两个实数根。方程的系数 a、b、c 从键盘输入,如果判别式(disc=b*b-4*a*c)小于 0,则要求重新输入 a、b、c 的值。例如,当 a=1,b=2,c=1 时,方程的两个根分别是:x1=-1.00,x2=-1.00。注意:部分源程序已给出。请勿改动函数中的其他任何内容,仅在横线上填入所编写的若干表达式或语句。试题程序:#includemath.h#includestdio.hvoid mai

2、n()double a,b,C,x1,x2,disc;doprintf(“Input a,b,c:“);scanf(“%1f,%1f,%1f”,&a,&b,&c);disc=b*b-4*a*c;if(disc0)printf(“disc=%1f/n Input again!/n“,disc);while( (1) );printf(“*the result*/n“);x1=(-b+ (2) (disc)/(2*a);x2=(-b- (3) (disc)/(2*a);printf(“/nx1=%6.21f/nx2=%6.21fkn“,x1,x2);(分数:30.00)填空项 1:_填空项 1:_

3、填空项 1:_二、改错题(总题数:1,分数:30.00)1.由 N 个有序整数组成的数列已放在一维数组中,下列给定程序函数 fun 的功能是:利用折半查找法查找整数 m 在数组中的位置。若找到,返回其下标值;否则,返回-1。折半查找的基本算法是:每次查找前先确定数组中待查的范围 low 和 high(lowhigh),然后用 m 与中间位置(mid)上元素的值进行比较。如果 m 的值大于中间位置元素的值,则下一次的查找范围落在中间位置之后的元素中;反之,下一次的查找范围落在中间位置之前的元素中,直到 lowhigh,查找结束。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main

4、函数,不得增行或删行,也不得更改程序的结构!试题程序:#includestdio.h#define N 10/*found*/void fun(int a,int m)int low=0,high=N-1,mid;while(low=high)mid=(low+high)/2;if(mamid)high=mid-1;/*found*/else if(mamid)low=mid+1;else return(mid);return(-1);void main()int i,aN=(-3,4,7,9,13,45,67,89,100,180),k,m;printf(“a 数组中的数据如下:“);for

5、i=0;iN;i+)printf(“%d“,ai);printf(“Enter m:“);scanf(“%d“,&m);k=fun(a,m);if(k=0)printf(“m=%d,index=%d/n“,m,k);else printf(“Not be found /n“);(分数:30.00)填空项 1:_三、编程题(总题数:1,分数:40.00)2.请编写函数 fun,其功能是:找出一维整型数组元素中最大的值所在的下标,并通过形参传回。数组元素中的值已在主函数中赋予。主函数中 x 是数组名。n 是 x 中的数据个数,max 存放最大值,index 存放最大值所在元素的下标。注意:部分源

6、程序已给出。请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。试题程序:#includetime.h#includestdlib.h#includestdio.hvoid fun(int a,int n,int*max,int*d)int i;*max=a0;*d=0;for(i=0;in;i+)/*将最大的元素放入指针 max 所指的单元,最大元素的下标放入指针 d 所指的单元*/if(*maxai)(*max=ai;*d=i;void main()int i,x20,max,index,n=10;scanf(unsigned) time (

7、NULL);for(i=0;i=n;i+)xi=rand()%50;printf(“%4d“,xi);/*输出一个随机数组*/printf(“/n“);fun(x,n,&max,&index);printf(“Max=%5d,Index=%4d/n“,max,index);(分数:40.00)_二级 C 语言机试-113 答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)请补充 main 函数,该函数的功能是求方程 ax2+bx+c=0 的两个实数根。方程的系数 a、b、c 从键盘输入,如果判别式(disc=b*b-4*a*c)小于 0,则要求重新输

8、入 a、b、c 的值。例如,当 a=1,b=2,c=1 时,方程的两个根分别是:x1=-1.00,x2=-1.00。注意:部分源程序已给出。请勿改动函数中的其他任何内容,仅在横线上填入所编写的若干表达式或语句。试题程序:#includemath.h#includestdio.hvoid main()double a,b,C,x1,x2,disc;doprintf(“Input a,b,c:“);scanf(“%1f,%1f,%1f”,&a,&b,&c);disc=b*b-4*a*c;if(disc0)printf(“disc=%1f/n Input again!/n“,disc);while(

9、 (1) );printf(“*the result*/n“);x1=(-b+ (2) (disc)/(2*a);x2=(-b- (3) (disc)/(2*a);printf(“/nx1=%6.21f/nx2=%6.21fkn“,x1,x2);(分数:30.00)填空项 1:_ (正确答案:disc0 或 0disc)解析:填空项 1:_ (正确答案:sqrt)解析:填空项 1:_ (正确答案:sqrt)解析:解析 本题考查的是 do-while 循环,第 1 处填空:disc0 或 0disc;本题引入#includemath.h头文件可知,可调用函数 sqrt。二、改错题(总题数:1,分

10、数:30.00)1.由 N 个有序整数组成的数列已放在一维数组中,下列给定程序函数 fun 的功能是:利用折半查找法查找整数 m 在数组中的位置。若找到,返回其下标值;否则,返回-1。折半查找的基本算法是:每次查找前先确定数组中待查的范围 low 和 high(lowhigh),然后用 m 与中间位置(mid)上元素的值进行比较。如果 m 的值大于中间位置元素的值,则下一次的查找范围落在中间位置之后的元素中;反之,下一次的查找范围落在中间位置之前的元素中,直到 lowhigh,查找结束。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结

11、构!试题程序:#includestdio.h#define N 10/*found*/void fun(int a,int m)int low=0,high=N-1,mid;while(low=high)mid=(low+high)/2;if(mamid)high=mid-1;/*found*/else if(mamid)low=mid+1;else return(mid);return(-1);void main()int i,aN=(-3,4,7,9,13,45,67,89,100,180),k,m;printf(“a 数组中的数据如下:“);for(i=0;iN;i+)printf(“%

12、d“,ai);printf(“Enter m:“);scanf(“%d“,&m);k=fun(a,m);if(k=0)printf(“m=%d,index=%d/n“,m,k);else printf(“Not be found /n“);(分数:30.00)填空项 1:_ (正确答案:(1)错误:void fun(int a,int m)正确:int fun(int a,int m)或 fun(int a,int m)(2)错误:else If(mamid)正确:else if(mamid))解析:解析 本题考查的是折半查找算法,函数的定义和 if-else 语句。首先,函数的定义需要考虑返

13、回值的类型,返回值为 int 类型。本题需求值,所以函数的返回值不能是 void 类型。因为如果略去函数类型标识符,系统默认为 int 类型所以函数定义应为 int fun(int a,int m)或 fun(int a,int m);关键词 if 要区分大小写,写错系统将无法识别。三、编程题(总题数:1,分数:40.00)2.请编写函数 fun,其功能是:找出一维整型数组元素中最大的值所在的下标,并通过形参传回。数组元素中的值已在主函数中赋予。主函数中 x 是数组名。n 是 x 中的数据个数,max 存放最大值,index 存放最大值所在元素的下标。注意:部分源程序已给出。请勿改动主函数 m

14、ain 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。试题程序:#includetime.h#includestdlib.h#includestdio.hvoid fun(int a,int n,int*max,int*d)int i;*max=a0;*d=0;for(i=0;in;i+)/*将最大的元素放入指针 max 所指的单元,最大元素的下标放入指针 d 所指的单元*/if(*maxai)(*max=ai;*d=i;void main()int i,x20,max,index,n=10;scanf(unsigned) time (NULL);for(i=0;i

15、n;i+)xi=rand()%50;printf(“%4d“,xi);/*输出一个随机数组*/printf(“/n“);fun(x,n,&max,&index);printf(“Max=%5d,Index=%4d/n“,max,index);(分数:40.00)_正确答案:(void fun(int a,int n,int*max,int*d)int i;*max=a0;*d=0;for(i=0;in;i+)/*将最大的元素放入指针 max 所指的单元,最大元素的下标放入指针 d 所指的单元*/if(*maxai)*max=ai;*d=i;)解析:解析 本题考查的是 for 循环和指针变量。通过 for 循环实现对数组的遍历,形参 max 和 d 都是指针型变量,所以引用它们指向的变量时要进行指针运算。先将*max=a0,在遍历中如果遇到比 max 大的元素,则将 ai赋值 max,下标 i 赋值*d。循环语句用来遍历数组元素,然后通过条件语句比较数组元素找到最大值。

展开阅读全文
相关资源
猜你喜欢
  • UNI 7003-1971 Measuring instruments Not go screw gauging members with profil with truncated flanks and collet for ISO metric threads with nominal diameter above 50 to 100 mm 《测量工具 .pdf UNI 7003-1971 Measuring instruments Not go screw gauging members with profil with truncated flanks and collet for ISO metric threads with nominal diameter above 50 to 100 mm 《测量工具 .pdf
  • UNI 7004-1971 Measuring instruments Screw gauging members with complete flanks (one half) and truncated flanks (one half) and collet for ISO metric threads with nominal diameter ab.pdf UNI 7004-1971 Measuring instruments Screw gauging members with complete flanks (one half) and truncated flanks (one half) and collet for ISO metric threads with nominal diameter ab.pdf
  • UNI 7005-1971 Measuring instruments Go gauging members with taper shaft for nominal sizes above 1 5 to 50 mm 《测量工具 标称尺寸超过1 5-50mm 的带圆锥手柄连接的过端光滑校准工具》.pdf UNI 7005-1971 Measuring instruments Go gauging members with taper shaft for nominal sizes above 1 5 to 50 mm 《测量工具 标称尺寸超过1 5-50mm 的带圆锥手柄连接的过端光滑校准工具》.pdf
  • UNI 7006-1971 Measuring instruments Not go gauging members with taper shaft for nominal sizes above 1 5 to 50 mm 《测量工具 标称尺寸超过1 5-50mm 的带圆锥手柄连接光滑不过端校准工具》.pdf UNI 7006-1971 Measuring instruments Not go gauging members with taper shaft for nominal sizes above 1 5 to 50 mm 《测量工具 标称尺寸超过1 5-50mm 的带圆锥手柄连接光滑不过端校准工具》.pdf
  • UNI 7007-1971 Measuring instruments Go and not go gauging members with collet for nominal sizes above 50 to 100 mm 《测量工具 标称尺寸超过50-100mm 的带轴套连接的光滑不过端校准工具》.pdf UNI 7007-1971 Measuring instruments Go and not go gauging members with collet for nominal sizes above 50 to 100 mm 《测量工具 标称尺寸超过50-100mm 的带轴套连接的光滑不过端校准工具》.pdf
  • UNI 7008-1971 Measuring instruments Handles for gauging members with taper shaft 《测量工具 带圆锥形连接手柄的端校准工具用曲柄》.pdf UNI 7008-1971 Measuring instruments Handles for gauging members with taper shaft 《测量工具 带圆锥形连接手柄的端校准工具用曲柄》.pdf
  • UNI 7009-1971 Measuring instruments Handles and screw for gauging members with collet 《测量工具 带轴套连接的端校准用曲柄和螺钉》.pdf UNI 7009-1971 Measuring instruments Handles and screw for gauging members with collet 《测量工具 带轴套连接的端校准用曲柄和螺钉》.pdf
  • UNI 7010-1971 Measuring instruments Gauges and check and setting gauges for ISO metric threads Distintion signs indications and check and their position on gauges and check and set.pdf UNI 7010-1971 Measuring instruments Gauges and check and setting gauges for ISO metric threads Distintion signs indications and check and their position on gauges and check and set.pdf
  • UNI 7035-1979 Plastics intended for contact with food Global migration test 《与食物接触的塑料材料 总游离试验》.pdf UNI 7035-1979 Plastics intended for contact with food Global migration test 《与食物接触的塑料材料 总游离试验》.pdf
  • 相关搜索

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

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