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

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

1、二级 C语言-49 及答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充函数 fun(),该函数的功能是:把字符下标能铍 2或 3整除的字符从字符串 str中删除,把剩余的字符重新保存在字符串 str中。字符串 str从键盘输入,其长度作为参数传入函数 fun()。 例如,输入“abcdefghijk”,输出“bfh”。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include stdio.h #define N 80 void

2、 fun(char s, int n) int i, k; U U /U /U; for(i=0; in; i+) sk+=si; if(U U /U /U) k-; U U /U /U; main() int i=0,strlen=0; char strN; clrscr(); printf(“/nInput a string:/n“);gets(str); while(stri!=/0) strlen+; i+; fun(str,strlen); printf(/n* display string */n“); puts(str); (分数:30.00)填空项 1:_二、B改错题/B(总题

3、数:1,分数:30.00)2.程序 MODI1.C中函数 fun和 funx的功能是:用二分法求方程 2x3-4x2+3x-6=0的一个根,并要求绝对误差不超过 0.001。例如,若给 m输入-100,给 n输入 90,则函数求得的一个根值为 2.000。请改正程序中的错误,使程序能输出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。文件 MODI1.C内容如下:#includestdio.h#includemath.hdouble funx(double x)return(2*x*x*x-4*x*x+3*x-6);double fun(double m,dou

4、ble n)/*found*/int r;r=(m+n)/2;/*found*/while(fabs(n-m)0.001)if(funx(r)*funx(n)0) m=r;else n=r;r=(m+n)/2;return r;void mainU /Udouble m,n,root;printf(“Enter m n:/n“);scanf(“%1f%1f“,(2)x0=x1,将 x1的值赋给 x0;(3)x1=cos(x0),求出一个新的 x1;(4)若 x0-x1的绝对值小于 0.000001,执行步骤(5),否则执行步骤(2);(5)所求 x1就是方程 cos(x)-x=0的一个实根,作

5、为函数值返回。程序将输出结果 Root=0739086。注意:部分源程序给出如下。请勿改动主函数数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序:#includeconio.h#includemath.h#includescdio.hdouble fun()main()double f=fun();printf(“Root=%f/n“,f);(分数:40.00)_二级 C语言-49 答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充函数 fun(),该函数的功能是:把字符下标能铍 2或 3整

6、除的字符从字符串 str中删除,把剩余的字符重新保存在字符串 str中。字符串 str从键盘输入,其长度作为参数传入函数 fun()。 例如,输入“abcdefghijk”,输出“bfh”。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include stdio.h #define N 80 void fun(char s, int n) int i, k; U U /U /U; for(i=0; in; i+) sk+=si; if(U U /U /U) k-; U U /U /U; m

7、ain() int i=0,strlen=0; char strN; clrscr(); printf(“/nInput a string:/n“);gets(str); while(stri!=/0) strlen+; i+; fun(str,strlen); printf(/n* display string */n“); puts(str); (分数:30.00)填空项 1:_ (正确答案:1k=0 2(i%2=0)|(i%3=0) 3sk=/0)解析:解析 填空 1;变量 k声明时没有初始化,所以在使用前要对它初始化。因为 k用作字符数组的下标,所以初始化为 0。填空 2:如果当前字符

8、的下标能被 2或 3整除,则不保存这个字符。填空 3:将所有字符下标能被 2或 3整除的字符从字符串中删除后,在字符串的最后还要加上结束标记符/0。二、B改错题/B(总题数:1,分数:30.00)2.程序 MODI1.C中函数 fun和 funx的功能是:用二分法求方程 2x3-4x2+3x-6=0的一个根,并要求绝对误差不超过 0.001。例如,若给 m输入-100,给 n输入 90,则函数求得的一个根值为 2.000。请改正程序中的错误,使程序能输出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。文件 MODI1.C内容如下:#includestdio.h#

9、includemath.hdouble funx(double x)return(2*x*x*x-4*x*x+3*x-6);double fun(double m,double n)/*found*/int r;r=(m+n)/2;/*found*/while(fabs(n-m)0.001)if(funx(r)*funx(n)0) m=r;else n=r;r=(m+n)/2;return r;void mainU /Udouble m,n,root;printf(“Enter m n:/n“);scanf(“%1f%1f“,(2)x0=x1,将 x1的值赋给 x0;(3)x1=cos(x0)

10、求出一个新的 x1;(4)若 x0-x1的绝对值小于 0.000001,执行步骤(5),否则执行步骤(2);(5)所求 x1就是方程 cos(x)-x=0的一个实根,作为函数值返回。程序将输出结果 Root=0739086。注意:部分源程序给出如下。请勿改动主函数数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序:#includeconio.h#includemath.h#includescdio.hdouble fun()main()double f=fun();printf(“Root=%f/n“,f);(分数:40.00)_正确答案:(double fun() float x1=0.0,x0; do x0=x1; /*调用 mafh库函数中的余弦函数*/ x1=cos(x0); /*当 xOx1的绝对值小于 lO的负 6次方时退出循环*/ while(fabs(x0-x1)=le-6); refurn x1; )解析:解析 本题关键字有:迭代法求方程的实根;循环语句。 dowhile 循环先执行循环中的语句,再判断表达式是否为真,为真则继续循环,为假则终止循环。因此,dowhile 循环的循环体至少要执行一次。 微分析 将给出的算法转换为合适的表达式,就可以求方程的一个实根了。

展开阅读全文
相关资源
猜你喜欢
  • EN ISO 17836-2004 en Thermal spraying - Determination of the deposition efficiency for thermal spraying《热喷涂 热喷涂沉积效率的测定 ISO 17836-2004》.pdf EN ISO 17836-2004 en Thermal spraying - Determination of the deposition efficiency for thermal spraying《热喷涂 热喷涂沉积效率的测定 ISO 17836-2004》.pdf
  • EN ISO 17836-2017 en Thermal spraying - Determination of the deposition efficiency for thermal spraying.pdf EN ISO 17836-2017 en Thermal spraying - Determination of the deposition efficiency for thermal spraying.pdf
  • EN ISO 17852-2008 en Water quality - Determination of mercury - Method using atomic fluorescence spectrometry《水质 汞含量的测定 原子荧光分光光度测定法[代替 CEN EN 13506]》.pdf EN ISO 17852-2008 en Water quality - Determination of mercury - Method using atomic fluorescence spectrometry《水质 汞含量的测定 原子荧光分光光度测定法[代替 CEN EN 13506]》.pdf
  • EN ISO 17855-1-2014 en Plastics - Polyethylene (PE) moulding and extrusion materials - Part 1 Designation system and basis for specifications《塑料 聚乙烯(PE)模塑和挤塑材料 第1部分 规格的标志法和基础(ISO 1.pdf EN ISO 17855-1-2014 en Plastics - Polyethylene (PE) moulding and extrusion materials - Part 1 Designation system and basis for specifications《塑料 聚乙烯(PE)模塑和挤塑材料 第1部分 规格的标志法和基础(ISO 1.pdf
  • EN ISO 17855-2-2016 en Plastics - Polyethylene (PE) moulding and extrusion materials - Part 2 Preparation of test specimens and determination of properties《塑料聚乙烯(PE)模塑和挤出材料第2部分 试样的.pdf EN ISO 17855-2-2016 en Plastics - Polyethylene (PE) moulding and extrusion materials - Part 2 Preparation of test specimens and determination of properties《塑料聚乙烯(PE)模塑和挤出材料第2部分 试样的.pdf
  • EN ISO 17864-2008 en Corrosion of metals and alloys - Determination of the critical pitting temperature under potientiostatic control《金属和合金的腐蚀 静电位控制下临界点蚀温度的测定》.pdf EN ISO 17864-2008 en Corrosion of metals and alloys - Determination of the critical pitting temperature under potientiostatic control《金属和合金的腐蚀 静电位控制下临界点蚀温度的测定》.pdf
  • EN ISO 17871-2015 en Gas cylinders - Quick-release cylinder valves - Specification and type testing《气瓶 速动气缸阀门 规格和类型测试(ISO 17871 2015)》.pdf EN ISO 17871-2015 en Gas cylinders - Quick-release cylinder valves - Specification and type testing《气瓶 速动气缸阀门 规格和类型测试(ISO 17871 2015)》.pdf
  • EN ISO 17872-2007 en Paints and varnishes - Guidelines for the introduction of scribe marks through coatings on metallic panels for corrosion testing《涂料和清漆 腐蚀试验用金属板涂层画线器标记的入门指南》.pdf EN ISO 17872-2007 en Paints and varnishes - Guidelines for the introduction of scribe marks through coatings on metallic panels for corrosion testing《涂料和清漆 腐蚀试验用金属板涂层画线器标记的入门指南》.pdf
  • EN ISO 17879-2017 en Gas cylinders - Self-closing cylinder valves - Specification and type testing.pdf EN ISO 17879-2017 en Gas cylinders - Self-closing cylinder valves - Specification and type testing.pdf
  • 相关搜索

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

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