[计算机类试卷]国家二级C语言机试(操作题)模拟试卷474及答案与解析.doc

上传人:Iclinic170 文档编号:498428 上传时间:2018-11-29 格式:DOC 页数:4 大小:38.50KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷474及答案与解析.doc_第1页
第1页 / 共4页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷474及答案与解析.doc_第2页
第2页 / 共4页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷474及答案与解析.doc_第3页
第3页 / 共4页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷474及答案与解析.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 474及答案与解析 一、程序填空题 1 下列给定程序中,函数 fun的功能是:计算如下公式前 n项的和,并作为函数值返回。 例如,当形参 n的值为 10时,函数返回值为 9 612558。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h double fun(int n) int i;double s, t; /*found*/ s= 【 1】; /*found*/ for(i=1 ; i = 【 2】; i+) t

2、2 0* i; 【 1】 S=s+(2 0*i一 1)*(2 0*i+1)/ 【 3】; retuen s; void main() int r1=一 1; while(n 0) printf(“Please input: (n 0): “); scanf(“ d“, &n); printf(“nThe result is: fn“, fun(n); 二 、程序修改题 2 下列给定程序中函数 fun的功能是:统计 substr所指的字符串在 str所指的字符串中出现的次数。 例如,若字符串为 1kaaas,子字符串为 as,则应输出 2。 请改正程序中的错误,使它能得出正确的结果。 注意:不

3、要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h int fun(char*str, char* substr) int i, j, k, num=0; /*found*/ for(i=0, stri, i+) for(j=i, k=0; substrk=str j; k+, j+) /*found*/ If(substrk+1=0) num+; break; return num; main() char str80, substr80; printf(“Input a string: “); gets(str); printf(“

4、Input a substring: “); gets(substr); printf(“ dn“, fun(str, substr); 三、程序设计题 3 编写函数 fun,其功能是:根据以下公式求 的值 (要求精度 0 0005,即某项小于 0 0005时停止迭代 )。 程序运行后,若输入精度 0 0005,则程序应输出为 3 140578。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio h #include conio h #include math h double

5、 fun(double eps)void main() double x; printf(“Input eps: “); scanf(“ 1f“, &x); printf(“neps= 1f, PI= 1fn“, x, fun(x); 国家二级 C语言机试(操作题)模拟试卷 474答案与解析 一、程序填空题 1 【正确答案】 (1)0 0 (2)n (3)(t*t) 【试题解析】 本题考查:变量初始化操作,需注意该变量是用做累加器还是累乘器; for循环语句。 填空 1:程序开始定义了变量 s,但没有对其进行初始化,根据公式及后面的程序可知变量 s用来存放公式的前 n项和,因此该变量应初始化为

6、 0 0。 填空 2:通过 for循环语句将表达式各项进行累加,结果存于变量 s中,循环变量 i的取值范围为 1n。 填空 3:根据题目要求确定表达式通项。前面已定义 t =2 0*i,因此此空应填( t*t)。 程序要求计算表达式的值时,一般都设定一个变量 s并赋初值。如果 s用来存放表达式的和, 则赋初值为 0;如果 s用来存放表达式的积,则赋初值为 1。 二、程序修改题 2 【正确答案】 (1)for(i=0; stri; i+) (2)if( substrk+1=0) 【试题解析】 本题考查: for循环语句的格式, for循环语句使用最为灵活,其一般形式为 for(表达式 1;表达式

7、 2;表达式 3),注意表达式之间使用 “; ”相隔;if条件语句的格式,其中 if关键字需要区别大小写,不能混淆使用。关键字是由C语言规定的具有特定意义的字符串,也称为保留字。用户定义的标识符不应与关键字相同, 并且关键字应小写。 先看循环条件 for(i=0, stri, i+),不难发现此处 for循环语句的格式有误,其中表达式之间应以 “; ”相隔;同时很容易发现 if条件语句处的关键字书写错误。 三、程序设计题 3 【正确答案】 double fun (double eps) double s=0 0,s1 =1 0; int n=1; while( s1 =eps) /*当某项大于

8、精度要求时,继续求下一项 */ s =s +s1; /*求和 */ s1=s1*n/(2*n+1); /*求多 项式的每一项 */ n+; return 2*s; 【试题解析】 本题考查:迭代法求给定多项式的值。迭代算法是让计算机对一组指令(或一定步骤)进行重复执行,在每次执行这组指令(或这些步骤)时,都从变量的原值推出它的一个新值。需要注意变量的数据类型以及赋初值操作。 首先应该定义 double类型变量,并且赋初值,用来存放多项式的某一项和最后的总和。从第二项开始以后的每一项都是其前面一项乘以 n/(2*n+1),程序中用 s1来表示每一项, s表示求和后的结果。需注意 s1和 s的初值都为 1 0,因为循环变量 从第二项开始累加。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 3464-1996 Aerospace Series Titanium Alloy TI-P64001 Annealed Plate 6 mm Less Than a Less Than or Equal to 100 mm Edition P 2《航空航天系列.钛合金TI-P64001退火板6 mm小于或等于a小于或等于100 mm》.pdf AECMA PREN 3464-1996 Aerospace Series Titanium Alloy TI-P64001 Annealed Plate 6 mm Less Than a Less Than or Equal to 100 mm Edition P 2《航空航天系列.钛合金TI-P64001退火板6 mm小于或等于a小于或等于100 mm》.pdf
  • AECMA PREN 3465-1995 Aerospace Series Titanium Alloy TI-P63001 not Heat Treated Grade 2 Forging Stock for Solution Treated and Aged Forgings a or D Less Than or Equal to 360 mm Edi.pdf AECMA PREN 3465-1995 Aerospace Series Titanium Alloy TI-P63001 not Heat Treated Grade 2 Forging Stock for Solution Treated and Aged Forgings a or D Less Than or Equal to 360 mm Edi.pdf
  • AECMA PREN 3466-1988 Titanium Alloy TI-P68 Solution Treated and Aged Rm Greater Than or Equal to 1000 MPa Bar for Machining De Less Than or Equal to 150 mm《钛合金TI-P68非热处理参照热处理溶液处理和老.pdf AECMA PREN 3466-1988 Titanium Alloy TI-P68 Solution Treated and Aged Rm Greater Than or Equal to 1000 MPa Bar for Machining De Less Than or Equal to 150 mm《钛合金TI-P68非热处理参照热处理溶液处理和老.pdf
  • AECMA PREN 3466-1994 Aerospace Series Titanium Alloy TI-P63001 Solution Treated and Aged Bar for Machining D Less Than or Equal to 150 mm Edition P 2《航空航天系列.钛合金 TI-P63001溶液处理和老化棒材直.pdf AECMA PREN 3466-1994 Aerospace Series Titanium Alloy TI-P63001 Solution Treated and Aged Bar for Machining D Less Than or Equal to 150 mm Edition P 2《航空航天系列.钛合金 TI-P63001溶液处理和老化棒材直.pdf
  • AECMA PREN 3467-1996 Aerospace Series Titanium Alloy TI-C64001 not Heat Treated Remelting Stock De Less Than or Equal to 300 mm Edition P 2《航空航天系列.钛合金 TI-C64001非热处理重熔锻件De小于或等于300 m.pdf AECMA PREN 3467-1996 Aerospace Series Titanium Alloy TI-C64001 not Heat Treated Remelting Stock De Less Than or Equal to 300 mm Edition P 2《航空航天系列.钛合金 TI-C64001非热处理重熔锻件De小于或等于300 m.pdf
  • AECMA PREN 3468-1988 Aerospace Series Steel FE-PA13 Softened 500 Less Than or Equal to Rm Less Than or Equal to 700 MPa Forgings De Less Than or Equal to 100 mm Issue P 1《航空航天系列.钢F.pdf AECMA PREN 3468-1988 Aerospace Series Steel FE-PA13 Softened 500 Less Than or Equal to Rm Less Than or Equal to 700 MPa Forgings De Less Than or Equal to 100 mm Issue P 1《航空航天系列.钢F.pdf
  • AECMA PREN 3469-2000 Aerospace Series Steel FE-PM1802 (X5CrNiCu15-5) Consumable Electrode Remelted Solution Treated and Precipitation Treated Forgings a or D Less than or Equal to t.pdf AECMA PREN 3469-2000 Aerospace Series Steel FE-PM1802 (X5CrNiCu15-5) Consumable Electrode Remelted Solution Treated and Precipitation Treated Forgings a or D Less than or Equal to t.pdf
  • AECMA PREN 3470-1998 Aerospace Series Steel FE-PM1503 (X3CrNiMoAI13-8-2) Vacuum Induction Melted and Consumable Electrode Remelted Solution Treated and Precipitation Treated Forgin.pdf AECMA PREN 3470-1998 Aerospace Series Steel FE-PM1503 (X3CrNiMoAI13-8-2) Vacuum Induction Melted and Consumable Electrode Remelted Solution Treated and Precipitation Treated Forgin.pdf
  • AECMA PREN 3471-1988 Aerospace Series Steel FE-PA18 Quenched and Cold Drawn Strip for Spring a Less Than or Equal to 4 0 mm Issue P 1《航空航天系列.钢FE-PA18卒火和冷拉带用于弹簧a小于或等于4 0mm P1板》.pdf AECMA PREN 3471-1988 Aerospace Series Steel FE-PA18 Quenched and Cold Drawn Strip for Spring a Less Than or Equal to 4 0 mm Issue P 1《航空航天系列.钢FE-PA18卒火和冷拉带用于弹簧a小于或等于4 0mm P1板》.pdf
  • 相关搜索

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

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