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

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

1、二级 C 语言机试-63 及答案解析(总分:71.00,做题时间:90 分钟)一、填空题(总题数:1,分数:1.00)1.请补充函数 fun(),该函数的功能是:寻找两个整数之间的的所有素数(包括这两个整数),把结果保存在数组 bb 中,函数返回素数的个数。例如,输入 6 和 21,则输出为:7 11 13 17 19 21。注意:部分源程序给出如下。请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。试题程序:#includeconio. h#includestdio. h#define N 1000int fun (int n, in

2、t m, int bb N)int i, j, k=0, flag;for (j=n; j=m; j+)【1】 ;for (i=2; ij; i+)if( 【2】 )flag=0;break;if( 【3】 )bb k+ =jreturn k;main ()int n=0,m=0, i, k;int bbN;clrscr ();printf (“Input n/n“);scanf (“%d“, printf (“Input m/n“);scanf (“%d“, for (i=0; im-n; i+)bbi=0;k=fun (n, m, bb);for (i=0; ik; i+)printf (

3、4d“,bb i);(分数:1.00)_二、改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun() 的功能是:计算并输出下列级数的的 N 项之和 SN,直到 SN+1 大于 q 为止,q 的值通过形参传入。SN=2/1+3/2+4/3+(N+1)/N例如,若 q 的值为 50.0,则函数值为 49.394948。请改正程序中的错误,使它能得出正确的结果。注意;不要改动 main 函数,不得增行或删行,也不得更改程序的结构试题程序:#include conio.h#include stdio. h/*found*/double fun(double q)int n; do

4、uble s,t;n=2;s=2.0;while (s=q)t=s/*found */s=s+ (n+1)/n;n+;printf (“n=%d/n “, n);/*found*/return s;main ()clrscr();printf (“%f/n “,fun (50);(分数:30.00)填空项 1:_三、编程题(总题数:1,分数:40.00)3.请编写函数 fun(),其功能是:计算并输出下列多项式的值。S=1+4/(1+2)+1/(1+2+3)+1/(1+2+3+n)例如,着主函数从键盘给 n 输入 50 后,则输出为 S=1.960784。注意:部分源程序给出如下。请勿改动主函

5、数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。试题程序:#include stdio.hdouble fun(int n)main ()int n;double s;printf (“/nInput n: “);scanf (“%d“, s=fun (n);printf (“/n/ns=%f/n/n“, s);(分数:40.00)_二级 C 语言机试-63 答案解析(总分:71.00,做题时间:90 分钟)一、填空题(总题数:1,分数:1.00)1.请补充函数 fun(),该函数的功能是:寻找两个整数之间的的所有素数(包括这两个整数),把结果保存在数组

6、 bb 中,函数返回素数的个数。例如,输入 6 和 21,则输出为:7 11 13 17 19 21。注意:部分源程序给出如下。请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。试题程序:#includeconio. h#includestdio. h#define N 1000int fun (int n, int m, int bb N)int i, j, k=0, flag;for (j=n; j=m; j+)【1】 ;for (i=2; ij; i+)if( 【2】 )flag=0;break;if( 【3】 )bb k+ =j

7、return k;main ()int n=0,m=0, i, k;int bbN;clrscr ();printf (“Input n/n“);scanf (“%d“, printf (“Input m/n“);scanf (“%d“, for (i=0; im-n; i+)bbi=0;k=fun (n, m, bb);for (i=0; ik; i+)printf (“%4d“,bb i);(分数:1.00)_解析:二、改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun() 的功能是:计算并输出下列级数的的 N 项之和 SN,直到 SN+1 大于 q 为止,q 的值通过

8、形参传入。SN=2/1+3/2+4/3+(N+1)/N例如,若 q 的值为 50.0,则函数值为 49.394948。请改正程序中的错误,使它能得出正确的结果。注意;不要改动 main 函数,不得增行或删行,也不得更改程序的结构试题程序:#include conio.h#include stdio. h/*found*/double fun(double q)int n; double s,t;n=2;s=2.0;while (s=q)t=s/*found */s=s+ (n+1)/n;n+;printf (“n=%d/n “, n);/*found*/return s;main ()clrs

9、cr();printf (“%f/n “,fun (50);(分数:30.00)填空项 1:_ (正确答案:(1)错误:double fun (double q) 正确:double fun (int q)(2)错误:s=s+(n+1)/n; 正确:s=s+(double)(n+1)/n;(3)错误:return s; 正确:return t;)解析:解析 该程序中多次出现了函数调用过程中定义混乱的错误,关于类似问题,我们在前面的试题中已经做过比较详细的解释,主要是对基础知识的把握。在这里我们再对函数调用规则做一简单说明。C 语言规定,在以下几种情况下可以不在调用函数前对被调用函数做类型说明。

10、1)如果函数的值(函数的返回值)是整型或字符型,可以不必进行说明,系统对它们自动按整型说明。但为清晰起见,建议都加以说明为好。(2)如果被调用函数的定义出现在主调函数之前,可以不必加以说明。因为编译系统已经先知道了已定义的函数类型,会自动处理的。也就是说,将被调用的函数的定义放在主调函数之前,就可以不必另加类型说明。(3)如果已在所有函数定义之前,在文件的开头,在函数的外部已说明了函数类型,则在各个主调函数中不必对所调用的函数再做类型说明。除了以上 3 种情况外,都应该按上述介绍的方法对所调用函数的返回值做类型说明,否则编译时就会出现错误。三、编程题(总题数:1,分数:40.00)3.请编写

11、函数 fun(),其功能是:计算并输出下列多项式的值。S=1+4/(1+2)+1/(1+2+3)+1/(1+2+3+n)例如,着主函数从键盘给 n 输入 50 后,则输出为 S=1.960784。注意:部分源程序给出如下。请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。试题程序:#include stdio.hdouble fun(int n)main ()int n;double s;printf (“/nInput n: “);scanf (“%d“, s=fun (n);printf (“/n/ns=%f/n/n“, s);(分数:40.00)_正确答案:(double fun (int n)int i;double s=0.0,s1=0.0;for(i=1;i=n;i+)s1=s1+i; /*求每项的分母*/s=s+1.0/s1; /*求 S=1+1/(1+2)+1/(1+2+3)+1/(1+2+3+n)*/return s;)解析:解析 该程序的数学思路是:在程序中输入 n 后,以前 n 项的和作为分母递加,由于 s1 是浮点类数据所以 s=s+1.0/s1; for 循环的作用是每一次循环给总结果 s 加上一项 1.0/s1。

展开阅读全文
相关资源
猜你喜欢
  • ASD-STAN PREN 2997-006-2015 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures - 65 to 175 continu.pdf ASD-STAN PREN 2997-006-2015 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures - 65 to 175 continu.pdf
  • ASD-STAN PREN 2997-007-2015 Aerospace Series Connectors Electrical Circular Coupled By Threaded Ring Fire-Resistant Or Non Fire-Resistant Operating Temperatures  65 To 175 Continuo.pdf ASD-STAN PREN 2997-007-2015 Aerospace Series Connectors Electrical Circular Coupled By Threaded Ring Fire-Resistant Or Non Fire-Resistant Operating Temperatures 65 To 175 Continuo.pdf
  • ASD-STAN PREN 2997-008-2005 Aerospace Series Connectors Electrical Circular Coupled by Threaded Ring Fire Resistant or Non Fire-Resistant Operating Temperatures - 65 Degrees to 175.pdf ASD-STAN PREN 2997-008-2005 Aerospace Series Connectors Electrical Circular Coupled by Threaded Ring Fire Resistant or Non Fire-Resistant Operating Temperatures - 65 Degrees to 175.pdf
  • ASD-STAN PREN 2997-009-2014 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures - 65 to 175 continu.pdf ASD-STAN PREN 2997-009-2014 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures - 65 to 175 continu.pdf
  • ASD-STAN PREN 2997-010-2014 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures - 65 to 175 continu.pdf ASD-STAN PREN 2997-010-2014 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures - 65 to 175 continu.pdf
  • ASD-STAN PREN 2997-011-2009 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures C 65 degree C to 17.pdf ASD-STAN PREN 2997-011-2009 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures C 65 degree C to 17.pdf
  • ASD-STAN PREN 2997-012-2006 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures C 65 to 175 continu.pdf ASD-STAN PREN 2997-012-2006 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures C 65 to 175 continu.pdf
  • ASD-STAN PREN 2997-013-2006 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures C 65 to 175 continu.pdf ASD-STAN PREN 2997-013-2006 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures C 65 to 175 continu.pdf
  • ASD-STAN PREN 2997-014-2014 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures C 65 to 175 continu.pdf ASD-STAN PREN 2997-014-2014 Aerospace series Connectors electrical circular coupled by threaded ring fire-resistant or non fire-resistant operating temperatures C 65 to 175 continu.pdf
  • 相关搜索

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

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