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

上传人:roleaisle130 文档编号:498645 上传时间:2018-11-29 格式:DOC 页数:6 大小:31.50KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷66及答案与解析.doc_第1页
第1页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷66及答案与解析.doc_第2页
第2页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷66及答案与解析.doc_第3页
第3页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷66及答案与解析.doc_第4页
第4页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷66及答案与解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 66及答案与解析 一、程序填空题 1 函数 fun的功能是:把形参 a所指数组中的最大值放在 a0中,接着求出 a所指数组中的最小值放在 a1中;再把 a所指数组元素中的次大值放在 a2中,把 a数组元素中的次小值放在 a3中;其余以此类推。例如:若 a所指数组中的数据最初排列为: 1、 4、 2、 3、 9、 6、 5、 8、 7,则按规则移动后,数据排列为: 9、 1、 8、2、 7、 3、 6、 4、 5。形参 n中存放 a所指数组中数据的个数。 请在程序的下划线处填入正确的内容并把下划线删除 ,使程序得出正确的结果。 注意:源程序存放在考生文件夹

2、下的 BLANK1 C 中。 不得增行或删行,也不得更改程序的结构 ! #inolude #define N 9 /*found*/ void fun(int _1_, int n) int i, j, max, min, px, pn, t ; /*found*/ for (i=0 ; iaj) min=aj; pn=j; ) i f(px!=i) t=ai; ai=max ; apx=t; i f(pn=i)pn=px ; i f(pn!=i+1) t=a2+1; a2+1=min; apn=t; ) main() int bN=1, 4, 2, 3, 9, 6, 5, 8, 7), i

3、 printf(“nThe original data: n“); for(i=0; i #define SIZE 20 fun(double*s, double*w) int k, i; double sum; for(k=2, i=0; i #define N 8 typedef struct char nLlm10; double s; STREC; double fun(STREC*a, STREC*b, int*n) main() STREC SN=“GA05“, 85), “GA03“, 76, “GA02“, 69, “GA04“, 85), “GA01“, 91, “GA07

4、 72), “GA08“, 64), “GA06“, 87; STREC hN, t; FILE*out; int i, j, n; double ave; ave=fun(s, h, &n); printf(“The d student data which is lower than 7 3f: n“, r1, ave), for(i=0; ihj s)t=hi; hi=hj; hj=t; for(i=0; in; i+) fprintf(out, “ 4 1fn“, hi s); fclose(out); 国 家二级 C语言机试(操作题)模拟试卷 66答案与解析 一、程序填空题 1

5、正确答案】 (1)*a (2)2 (3)i+1 【试题解析】 第一空:主函数内 fun函数的调用 “fun(b, N); ”,其中 b为整型数组名,故 fun函数的第一参数为整型指针,又根据 “max=aj”可知第一个参数名为 a,故第一空处为 “*a”。 第二空:根据题意 a所指数组中的最大值放在 a0中,接着求出 a所指数组中的最小值放在 a1中;再把 a所指数组元素中的次大值放在 a2中,把 a数组元素中的次小值放在 a3中,升序排序 和降序排序的下标变化是每次在前一次的基础上+2,即 a0、 a2、 a4 降序排序, a1、 a3、 a5 升序排序,故第二空应为“2”。 第三空:选择

6、排序法中的升序排序,首先从数组中挑选一个最小的元素,把它和第一元素交换,接着从剩下的 n-1个元素中再挑出一个最小的元素,把它和第二个元素交换,不断重复以上过程,直到比较完最后两个元素。故内层循环变量 i应该从 i+1开始,因此第三空处应为 “i+1”。 二、程序修改题 2 【正确答案】 (1)sum=0 0; (2)if(i+1) 5=0) 【试题解析】 (1)在第一标识下 “sun=0 0; ”,根据题意,这是给 sum赋值,而sun没有定义编译时会提示错误,应改为 “sum=0 0; ”。 (2)错误标识下的 if判断语句是依顺序取 5个字符, if中的逻辑表达式语法有误,由于 1 5恒

7、等于 1,所以 i+1 5也就等价于 i+1了,所以将 “if(i+1 5=0)”改为“if(i+1) 5=0)”,此处主要注意的是运算符的优先级。 三、程序设计题 3 【正确答案】 int i; double ave=0 0; *n=0; for(i=0; iN; i+)ave=ave+ai s; ave/=N; /*计算平均值 */ for(i=0; iN; i+) if(ai save) /*把低于平均值的记录存放到 b所指的数组中 */ b*n=ai; (*n)+; /*人数加 1*/ return ave; /*返回平均值 */ 【试题解析】 (1)首先,通过循环求总分,然后求得平均分。 (2)在循环中,进行平均分与每个成绩进行比较,并将满足条件的数据存入数组及对其进行累加。

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