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

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

1、国家二级 C语言机试(操作题)模拟试卷 528及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是: 计算形参 x所指数组中 N个数的平均值(规定所有数均为正数),作为函数值返回,并将大于平均值的数放在形参 y所指数组中,在主函数中输出。 例如,有 10个正数: 46、 30、 32、 40、 6、 17、 45、 15、 48、 26,其平均值为30. 500000。 主函数中输出: 46 32 40 45 48。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在 文件 BLANK1.C中。 不得增行或删行,也不得更改程序的结构! 试题

2、程序: #include stdlib.h #include stdio.h #define N 10 double fun (double x , double * y) int i, j; double av; *found* av =【 1】 ; *found* for(i=0; i N; i+) av = av +【 2】 ; for(i=j=0; i N; i+) *found* if(xi av)y【 3】 =Xi; yj=一 1; return av; main () int i; double xN, yN ; for(i=0; i N; i+) xi =rand() 00 5

3、0; printf (“ 4 .0f “, xi) ; printf (“n“) ; printf (“nThe average is: f n“, fun(x, y); for(i=0; yi =0; i+) printf(“ 5 1f“, yi); printf(“ n“); 二、程序修改题 2 下列给定程序中,函数 fun的功能是:根据整型参数 m,计算如下公式的值。例如,若 m= 2000,则应输出 0.000160。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODI1.C中,不要改动 main函数,不得增行或删行 ,也不得更改程序的结构! 试题程序: #i

4、nclude stdlib .h #include conio.h #include stdio.h *found* fun (int m) double y=0, d; int i;*found* for (i =100, i =m, i+=100) d = (double) i * (double) i; y+=1.0/d; return (y) ; void main () int n=2000; system (“CLS“) ; printf(“nThe result is 1fn“, fun(n); 三、程序设计题 3 已知学生的记录由学号和学习成绩构成, N名学生的数据已存入 a结

5、构体数组中。 请编写函数 fun,该函数的功能是:找出成绩最低的学生记录,通过形参返回主函数(规定只有一个最低分)。已给出函数的首部,请完成该函数。 注意:部分源程序在文件 PROGl.C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio .h #include string .h #include conio .h #include stdlib.h #de fine N 10 typedef struct ss char num10 ; int s; STU; fun(STU a, STU *s)

6、 void main () FILE *wf; STU aN = “A01“, 81 , “A02“, A05“, 77, “A06“, 90, “A07“, 79, int i; system (“CLS“); printf (“ * The original data*n“); printf (“No = s Mark = dn“, a i.nim, ai.s); printf (“* THE RESULT * n“), printf (“The lowest: s, dn“, m.num, m.s); *found* wf=fopen (“out.dat“, “w“) ; fprintf

7、 (wf, “ s, d“, m.num, m.s); fclose (wf); * 国家二级 C语言机试(操作题)模拟试卷 528答案与解析 一、程序填空题 1 【正确答案】 (1)0.0 (2)xi/N (3)j+ 【试题解析】 填空 1:通过上面的程序可以看出此空考的是给变量赋初值, av代表的是平均值,因此 av的初值应该是 0.0。 填空 2:通过 for循环可知,此空代表求平均值,因此应该填写 xi/N。 填空 3:先把大于平均值的数放在形参 y所指数组中,然后使下标值加 1,因此此空应该填 j+。 二、程序修改题 2 【正确答案】 (1)double fun( int m) (2

8、)for(i=100; i =m, i+=100) 【试题解析】 (1)题目要求在函数 fun中求级数前 m项和,可用循环语句,每次计算级数中 的一项,然后累加。第一处错误在于定义 fun(int m),由函数的返回值y可知此处应该定义为 double fun(int m)。 (2)for(i=100, i =m, i+=100)中是一个简单的语法错误。 for循环语句的形式为for(表达式 1;表达式 2;表达式 3),其表达式之间应以 “; “相隔。 三、程序设计题 3 【正确答案】 fun( STU a, STU *s) int i; *s=a0; *先认为第 1个值最小 * for(i=0; i N; i+) *如果在循环的过程中再发现比第 1个值更小 的则赋给 *s*/ if( s一 s ai s) *s=ai; 【试题解析】 找出结构体数组元素中的最小值。先认为第 1个值最小,即*s=a0;,如果在循环的过程中发现比第 1个值更小的,就将指针 s指向该元素,直到找到最小元素。另外,本题还涉及结构体中的指向运算符,请考生注意。

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