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

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

1、国家二级 C语言机试(操作题)模拟试卷 323及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是:计算形参 X所指数组中 N个数的平均值 (规定所有数均为正数 ),将所指数组中大于平均值的数据移至数组的前部,小于等于平均值的数据移至 x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。 例如,有 10个正数: 46、 30、 32、 40、 6、 17、 45、 15、 48、 26,平均值为30 500000。 移动后的输出为: 46、 32、 40、 45、 48、 30、 6、 17、 15、 260 请在程序的 下画线处填入正确的内容并把下画线删

2、除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1 C中。 不得增行或删行,也不得更改程序的结构 ! 试题程序: 1 #include Stdlib h 2 #include stdio h 3 #define N 10 4 double fun(double*x) 5 int i, j; double s, av, yN; 6 s=0; 7 for(i=0; i N; i+)s=s+xi; 8 *found* 9 av=【 1】 ; 10 for(i=j=0; i N; i+) 11 if(xi av) 12 *found* 13 y【 2】 =xi; 14 xi= 1; 15

3、 for(i=0; i N; i+) 16 *found* 17 if(xi!= 【 3】 )yj+=xi; 18 for(i=0; i N; i+)xi=yi; 19 return av; 20 21 main() 22 int i; double xN; 23 for(i=0; i N; i+) 24 xi=rand() 50; 25 printf(“ 4 0 f“, xi); ) 26 printf(“ n“); 27 printf(“ nThe average is: f n“, fun(x); 28 printf(“ nThe result: n“, fun(x); 29 for(i

4、0; i N; i+) 30 printf(“ 5 0 f“, xi); 31 printf(“ n“); 32 二、程序修改题 2 下列给定程序中,函数 fun的功能是:求 s的值。例如,当 k为 10时,函数的值应为1 533852。请改正程序中的错误,使它能得出正确的结果。注意:部分源程序在文件 MODI1 C中,不要改动 main函数,不得增行或删行,也不得更改程序的结构 !试题程序: #include stdlib h #include conio h #include stdio h#include math h *found* fun(int k) int n; float s

5、 w,p, q; n=1; s=1 0; while(n =k) w=2 0*n; P=w一 1 0; q=w+1 0; S=s*w*w p q; n+; *found* return svoid main() system(“CLS“), printf(“ f n“, fun(10); 三、程序设计题 3 学生的记录由学号和成绩组成, N名学生的数据已在主函数中放入结构体数组 s中,请编写函数 fun,其功能是:把低于平均分的学生数据放入 b所指的数组中,低于平均分的学生人数通过形参 n传回,平均分通过函数值返回。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容

6、仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio h #define N 8 typedef struct char num10; double s; STREC; double fun(STREC*a, STREC*b, int*n) void main() STREC sN=“GA05“, 85, “GA03“, 76, “GA02“, 69, “GA04“, 85,“GAO1“, 91, “GA07“, 72, “GA08“, 64, “GA06“, 87; STREC hN; int i, n; double ave; ave=fun(s,

7、h, n); printf(“The d student data which is lower than 7 3 f: n“, n, ave); for(i=0; i n; i+) *输出成绩低于平均值的学生记录 * printf(“ s 4 1 f n“, hi num, hi s); printf(“ n“); 国家二级 C语言机试(操作题)模拟试卷 323答案与解析 一、程序填空题 1 【正确答案】 (1)s N (2)j+ (3) 1 【试题解析】 填空 1:由原程序可知, av代表的是平均值,而平均 值的求法是所有数的总和除以数的个数,因而本空应该填写 s N。 填空 2: y数组

8、代表暂时存放 x数组, if(xi av)表达的是当 x数组中的数大于平均值时,应该把这些大于平均值的数放在 y数组的前半部分,因而此空应该填yj+。 填空 3:此空表明当 xi不等于什么时, xi中的数要赋值给 y数组,由题意可知此空只能填写 1。 二、程序修改题 2 【正确答案】 (1)float fun(int k) (2)return s; 【试题解析】 (1)此处为函数定义错误,根据返回值的类型可知函数类型标 识符应为 double。 (2)语法错误。 三、程序设计题 3 【正确答案】 double fun(STREC *a, STREC *b, int, *n) int i, j=0; double av=0 0; for(i=0; i N; i+) av=av+ai s; av=av N; *求平均值 * for(i=0; i N; i+) if(ai s av) bj+=ai; *将低于平均值的学生记录存入结构体数组 b中 * *n=j; *指针传回低于平均值的学生人数 * return av; *返回平均值 * 【试题解析】 本题使用循环语句和条件判断语句来实现程序操作,第 1个循环语句的作用是求出总分,然后求出平均分 av。第 2个循环的作用是将分数低于平均分的学生记录存入结构体数组 b中。

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