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

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

1、国家二级 C语言机试(操作题)模拟试卷 620及答案与解析 一、程序填空题 1 使用 VC+2010打开考生文件夹下 blank1中的解决方案。此解决方案的项目中包含一个源程序文件 blank1 c。在此程序中,函数 fun的功能是计算下式直到 并将计算结果作为函数值返回。例如,若形参 e的值为 1e-3,函数的返回值为 2 985678。请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。注意:部分源程序给出如下。不得增行或删行,也不得更改程序的结构 !试题程序: #include stdio hdouble fun(double e)int i; double s, x;

2、 *found* s=0; i=【 1】; x=1 0; while(x e) *found*【 2】;*found* x=(2 0*i-1) (【 3】 )*(2 0*i); s=s+x; return s; main()double e=1e-3; printf(“ nThe result is: f n“, fun(e); 二、程序修改 题 2 使用 VC+2010打开考生文件夹下 modi1中的解决方案。此解决方案的项目中包含一个源程序文件 modi1 c。在此程序中,函数 fun的功能是:按顺序给 s所指数组中的元素赋予从 2开始的偶数,然后再按顺序对每 5个元素求一个平均值,并将这

3、些值依次存放在 w所指的数组中。若 s所指数组中元素的个数不是 5的倍数,则多余部分忽略不计。 例如, s所指数组有 14个元素,则只对前 10个元素进行处理,不对最后的 4个元素求平均值。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行, 也不得更改程序的结构 ! 试题程序: #include stdio h #define SIZE20 fun(double*s, double*w) int k, i; double sum; for(k=2, i=0; i SIZE; i+) si=k; k+=2; *found* sun=0 0; for(k=

4、0, i=0; i SIZE; i+) sum+=si; *found* if(i+1 5=0) wk=sum 5; sum=0; k+; return k; main() double aSIZE, bSIZE 5; int i, k; k=fun(a, b); printf(“The original clata: n“); for(i=0; i SIZE; i+) if(i 5=0)printf(“ n“); printf(“ 4 0f“, ai); printf(“ n nThe result: n“); for(i=0; i k; i+) printf(“ 6 2f“, hi); p

5、rintf(“ n n“); 三、程序设计题 3 使用 VC+2010打开考生文件夹下 prog1中的解决方案。此解决方案的项目中包含一个源程序文件 progl c。在此程序中,请编写函数 fun,函数的功能是查找 x在 s所指数组中下标的位置,并作为函数值返回,若 x不存在,则返回 -1。 注意:部分源程序在文件 PROG1 C文件中,请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio h #include stdlib h #define N15 void NONO(); int fun(int*s,

6、int x) main() int aN=29, 13, 5, 22, 10, 9, 3, 18, 22, 25, 14, 15, 2, 7, 27, i, x,index; printf(“a数组中的数据: n“); for(i=0; i N; i+) printf(“ 4d“, ai); printf(“ n“); printf(“给 x输入待查找的数: “); scarlf(“ d“, &x); index=fun(a, X); printf(“index= d n“, index); NONO(); void NONO() *本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。

7、 * FILE*fp, *wf; int i, j, a10, x, index; fp=fopen(“in dat“, “r“); wf=fopen(“out dat“, “w“); for(i=0; i 10; i+) for(j=0; j 10; j+) fscanf(fp, “ d“, &aj); fscanf(fp, “ d“, &x); index=gun(a, x); fprintf(wf, “ d n“, index); fclose(fp); fclose(wf); 国家二级 C语言机试(操作题)模拟试卷 620答案与解析 一、程序填空题 1 【正确答案】 (1)0 (2)i

8、或 +i或 i+=1或 i=i+1 (3)2 0*i 【试题解析】 填空 1:循环变量 i从 1开始参加运算,但是在每次循环的开始 i都进行自加 1操作,故 i应赋初值为 0。 填空 2:循环变量 i自增 1运算。 填空 3:根据公式确定表达式通项。注意 x为 double型,故应将 i变为 double型再进行运算。 二、程序修改题 2 【正确答案】 (1)sum=0 0; (2)if(i+1) 5=0) 【试题解析】 (1)变量 sum书写错误。 (2)循环条件 if(i+1 5=0)是一个运算逻辑错误,应先计算 i+1,再对 5求余。 三、程序设计题 3 【正确答案】 int fun(int*s, int x) int i; for(i=0; i N; i+) if(x=si)return i; return-l; 【试题解析】 要找出数组中指定数据的下标,首先定义变量 i用于存放数组下标,然后使用循环语句对数组进行遍历,依次取出一个数组元素与指定的数进行比较,若相等,则返回该元素的下标,否则继续判断下一个元素,直到数组结束。若数组结束时仍没有找到与指定数相等的元素,则返回 -1。

展开阅读全文
相关资源
猜你喜欢
  • 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