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

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

1、二级 C 语言-65 及答案解析(总分:71.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:1.00)1.请补充函数 fun,其功能是:计算并输出给定 10 个数的方差: (分数:1.00)填空项 1:_二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中函数 fun 的功能是:求出如下分数序列的前 n 项之和,和值通过函数值返回。 (分数:30.00)填空项 1:_三、B编程题/B(总题数:1,分数:40.00)3.编写函数 fun,其功能是:利用下面的简单迭代方法求方程 cos(x)-x=0 的一个实根。xn+1=cos(xn)迭代步骤如下:(1)取 x1初

2、值为 0.0;(2)x0=x1,将 x1的值赋给 x0;(3)x1=cos(x0),求出一个新的 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()

3、printf(“Root=%f/n“,f);(分数:40.00)_二级 C 语言-65 答案解析(总分:71.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:1.00)1.请补充函数 fun,其功能是:计算并输出给定 10 个数的方差: (分数:1.00)填空项 1:_ (正确答案:1 sum+=xi 2 abs+=(xi-avg)*(xi-avg) 3 sqrt(abs/10))解析:解析 填空 1:根据求方差的公式可知,首先要求出 10 个数的平均值,此处是利用 for 循环对 10个数求累加和。填空 2:使用 for 循环求出每个数与平均值之差的平方和。填空 3:通过开

4、方,求出 10 个数的方差,此处需要注意对库函数 sqrt()的调用。二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中函数 fun 的功能是:求出如下分数序列的前 n 项之和,和值通过函数值返回。 (分数:30.00)填空项 1:_ (正确答案:(1)错误:fun(int n) 正确:double fun(int n) (2)错误:s=s+(Double)a/b; 正确:s=s+(double)a/b;)解析:解析 本题考查函数的定义规则。函数定义的一般形式为类型标识符函数名(形式参数表列)函数体。fun 函数中,最后返回的是变量 s,由变量 s 的定义可知,返回值是 dou

5、ble 型,所以 fun 函数定义时应明确注明标识符 double 类型。double 为书写问题,写程序时切记书写格式。三、B编程题/B(总题数:1,分数:40.00)3.编写函数 fun,其功能是:利用下面的简单迭代方法求方程 cos(x)-x=0 的一个实根。xn+1=cos(xn)迭代步骤如下:(1)取 x1初值为 0.0;(2)x0=x1,将 x1的值赋给 x0;(3)x1=cos(x0),求出一个新的 x1;(4)若 x0-x1的绝对值小于 0.000001,执行步骤(5),否则执行步骤(2);(5)所求 x1就是方程 cos(x)-x=0 的一个实根,作为函数值返回。程序将输出结

6、果 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 循环的循环体至少要执行一次。 微分析 将给出的算法转换为合适的表达式,就可以求方程的一个实根了。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO IEC 20246-2017 Software and systems engineering Work product reviews《软件和系统工程 工作产品审查》.pdf BS ISO IEC 20246-2017 Software and systems engineering Work product reviews《软件和系统工程 工作产品审查》.pdf
  • BS ISO IEC 20648-2016 Information technology TLS specification for storage systems《信息技术 存储系统的TLS规格》.pdf BS ISO IEC 20648-2016 Information technology TLS specification for storage systems《信息技术 存储系统的TLS规格》.pdf
  • BS ISO IEC 20741-2017 Systems and software engineering Guideline for the evaluation and selection of software engineering tools《系统和软件工程 软件工程工具评估和选择指南》.pdf BS ISO IEC 20741-2017 Systems and software engineering Guideline for the evaluation and selection of software engineering tools《系统和软件工程 软件工程工具评估和选择指南》.pdf
  • BS ISO IEC 20919-2016 Information technology Linear Tape File System (LTFS) Format Specification《信息技术 线性磁带文件系统 (LTFS) 格式规格》.pdf BS ISO IEC 20919-2016 Information technology Linear Tape File System (LTFS) Format Specification《信息技术 线性磁带文件系统 (LTFS) 格式规格》.pdf
  • BS ISO IEC 20922-2016 Information technology Message Queuing Telemetry Transport (MQTT) v3 1 1《信息技术 消息队列遥测传输 (MQTT)伏3 1 1》.pdf BS ISO IEC 20922-2016 Information technology Message Queuing Telemetry Transport (MQTT) v3 1 1《信息技术 消息队列遥测传输 (MQTT)伏3 1 1》.pdf
  • BS ISO IEC 20933-2016 Information technology Distributed Application Platforms and Services (DAPS) Access Systems《信息技术 分布式应用程序平台和服务 (DAPS) 接入系统》.pdf BS ISO IEC 20933-2016 Information technology Distributed Application Platforms and Services (DAPS) Access Systems《信息技术 分布式应用程序平台和服务 (DAPS) 接入系统》.pdf
  • BS ISO IEC 20944-1-2013 Information technology Metadata Registries Interoperability and Bindings (MDR-IB) Framework common vocabulary and common provisions for conformance.pdf BS ISO IEC 20944-1-2013 Information technology Metadata Registries Interoperability and Bindings (MDR-IB) Framework common vocabulary and common provisions for conformance.pdf
  • BS ISO IEC 20944-2-2013 Information technology Metadata Registries Interoperability and Bindings (MDR-IB) Coding bindings《信息技术 元数据登记系统互用性和绑定(MDR-IB) 编码绑定》.pdf BS ISO IEC 20944-2-2013 Information technology Metadata Registries Interoperability and Bindings (MDR-IB) Coding bindings《信息技术 元数据登记系统互用性和绑定(MDR-IB) 编码绑定》.pdf
  • BS ISO IEC 20944-3-2013 Information technology Metadata Registries Interoperability and Bindings (MDR-IB) API bindings《信息技术 元数据登记系统互用性和绑定(MDR-IB) API绑定》.pdf BS ISO IEC 20944-3-2013 Information technology Metadata Registries Interoperability and Bindings (MDR-IB) API bindings《信息技术 元数据登记系统互用性和绑定(MDR-IB) API绑定》.pdf
  • 相关搜索

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

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