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

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

1、二级 C语言机试-64 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:33.00)1.请补充函数 fun(),该函数的功能是:计算下面公式的值 (k50): (分数:33.00)填空项 1:_二、改错题(总题数:1,分数:33.00)2.下列给定程序中,函数 fun()的功能是:输出 M行 N列整数方阵,然后求两条对角线上的各元素的平方和,返回此和数。请改正程序中的错误,使它能得到正确结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。试题程序:#include conioh#include stdioh#define M 5int

2、fun(int n,int xxM)int i,j,sum=O;printf(“/nThe %d x %d matrix:/n“,M,M);for(i=0;iN;i+)for(j=0;jM;j+)/*found*/printf(“%4d“,xxi j);/*found*/printf(/n);for(i=0;in;i+)sum+=xxii*xxii+xxin-i-1*xxin-i-1;return(sum);main()int aaMM=3,12,4,24,35,11,3, 3,7, 56,61,27,58,49,24,17,28,7,36,85,15,33,5,24,9;clrscr();p

3、rintf(“/nThe result of all elements on 2diagnals iS%d“,fun(M,aa);(分数:33.00)填空项 1:_三、编程题(总题数:1,分数:34.00)3.请编写函数 fun(),其功能是:计算并输出下列多项式值。S(1+1/2)+(1/3+1/4)+(1/(2n1)+l/2n)例如,若主函数从键盘给 n输入 12后,则输出为 S=3.775958。n的值要求大于 1但不大于 100。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入所编写的若干语句。试题程序:#includestdio

4、hdouble fun(int n)main()int n;double s;printf(“/nlnput n:“);scanf(“%d“,&n);s=fun(n); printf(“/ns=%f/n“,s);(分数:34.00)_二级 C语言机试-64 答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:33.00)1.请补充函数 fun(),该函数的功能是:计算下面公式的值 (k50): (分数:33.00)填空项 1:_ (正确答案:1 1 2 k=n 3s*=f/p)解析:解析 填空 1:变量 s存放最后的计算结果,由公式可知,计算结果为多个数的乘积,所

5、以 s应该初始化为 1。填空 2: for 循环的次数为 n,由公式可知,k 的取值应该从 1到 n。填空 3:for 循环求出的 f为(2k-1)2k+l,for 循环求出的 p为(2k +1)2k-1,由公式可知,每项即为 f/p,所以此处应填s*=f/p。二、改错题(总题数:1,分数:33.00)2.下列给定程序中,函数 fun()的功能是:输出 M行 N列整数方阵,然后求两条对角线上的各元素的平方和,返回此和数。请改正程序中的错误,使它能得到正确结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。试题程序:#include conioh#include stdio

6、h#define M 5int fun(int n,int xxM)int i,j,sum=O;printf(“/nThe %d x %d matrix:/n“,M,M);for(i=0;iN;i+)for(j=0;jM;j+)/*found*/printf(“%4d“,xxi j);/*found*/printf(/n);for(i=0;in;i+)sum+=xxii*xxii+xxin-i-1*xxin-i-1;return(sum);main()int aaMM=3,12,4,24,35,11,3, 3,7, 56,61,27,58,49,24,17,28,7,36,85,15,33,5

7、24,9;clrscr();printf(“/nThe result of all elements on 2diagnals iS%d“,fun(M,aa);(分数:33.00)填空项 1:_ (正确答案:(1)错误:printf(“%4d“,xxij); 正确:printf(“%4d“,xxij):(2) 错误:printf(/n); 正确:printr(“/n“);)解析:解析 错误 1:此处考查的是对二维数组的引用方法。错误 2:此处考查的是输出语句的语法,括号中应该用双引号,而不是单引号。三、编程题(总题数:1,分数:34.00)3.请编写函数 fun(),其功能是:计算并输出下列

8、多项式值。S(1+1/2)+(1/3+1/4)+(1/(2n1)+l/2n)例如,若主函数从键盘给 n输入 12后,则输出为 S=3.775958。n的值要求大于 1但不大于 100。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入所编写的若干语句。试题程序:#includestdiohdouble fun(int n)main()int n;double s;printf(“/nlnput n:“);scanf(“%d“,&n);s=fun(n); printf(“/ns=%f/n“,s);(分数:34.00)_正确答案:(double fun(int n) int i;double s=0.0;for(i=1;i=n;i+) /*计算 S=(1+l/2)+(1/3+1/4)+(1/(2n-1)+1/2n)*/s=s+(1.0/(2*i-1)+1.0/(2*i);return s;)解析:解析 本题中 s=s+(1.0/(2*i-1)+1.0/(2*i);语句是用 C程序去表达题目中的每一项,这是关键,其他问题不难理解。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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