【计算机类职业资格】二级C语言-255及答案解析.doc

上传人:medalangle361 文档编号:1325084 上传时间:2019-10-17 格式:DOC 页数:5 大小:37KB
下载 相关 举报
【计算机类职业资格】二级C语言-255及答案解析.doc_第1页
第1页 / 共5页
【计算机类职业资格】二级C语言-255及答案解析.doc_第2页
第2页 / 共5页
【计算机类职业资格】二级C语言-255及答案解析.doc_第3页
第3页 / 共5页
【计算机类职业资格】二级C语言-255及答案解析.doc_第4页
第4页 / 共5页
【计算机类职业资格】二级C语言-255及答案解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 C 语言-255 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)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 26。 请在程序的下划线处填入正确的内容

2、并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! 给定源程序如下。 #includestdlib.h #includestdio.h #define N 10 double fun(double*x) int i,j;double s,av,yN; s=0; for(i=0;iN;i+)s=s+xi; /*found*/ av= 1; for(i=j=0;iN;i+) if(xiav) /*found*/ y 2=xi;xi=-1; for(i=0;jN;i+) /*found*/ if(xi!= 3)yj

3、xi; for(i=0;iN;i+)xi=yi; return av; main() int i; double xN= 46,30,32,40,6,17,45,15,48,26; for(i=0;iN;i+)printf(“%4.0f“,xi); printf(“/n“); printf(“/nThe average is:%f/n“,fun(x); printf(“/nThe result:/n“,fun(x); for(i=0;iN;i+)printf(“%5.0f“,xi); printf(“/n“): (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.给定程序

4、 MODI1.C 的功能是读入一个英文文本行,将其中每个单词的第一个字母改成大写,然后输出此文本行(这里的“单词”是指由空格隔开的字符串)。 例如,若输入 I am a student to take the examination., 则应输出 I Am A Student To Take The Examination.。 请改正程序中的错误,使程序能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序如下。 #includectype.h #includestring.h /*found*/ includestdio.h /*found*/

5、 void upfst(char p) int k=0; for(;*p;p+) if(k) if(*p=“)k=0; else if(*P!=“) k=1;*p=toupper(*p); main() char chrstr81; printf(“/nPlease enter an English text line:“); gets(chrstr); printf(“/n/nBefore changing:/n%s“,chrstr); upfst(chrstr); printf(“/nAfter changing:/n%s/n“,chrstr); (分数:30.00)三、程序设计题(总题数

6、1,分数:40.00)3.程序定义了 NN 的二维数组,并在主函数中赋值。请编写函数 fun,函数的功能是求出数组周边元索的平均值并作为函数值返给主函数中的 s。 例如:a 数组中的值为 (分数:40.00)_二级 C 语言-255 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是计算形参 x 所指数组中 N 个数的平均值(规定所有数均为正数),将所指数组中大于平均值的数据移至数组的前部,小于等于平均值的数据移至 x 所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。 例如,有 1

7、0 个正数:46 30 32 40 6 17 45 15 48 26,平均值为 30.500000。 移动后的输出为 46 32 40 45 48 30 6 17 15 26。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! 给定源程序如下。 #includestdlib.h #includestdio.h #define N 10 double fun(double*x) int i,j;double s,av,yN; s=0; for(i=0;iN;i+)s=s+xi;

8、 /*found*/ av= 1; for(i=j=0;iN;i+) if(xiav) /*found*/ y 2=xi;xi=-1; for(i=0;jN;i+) /*found*/ if(xi!= 3)yj+=xi; for(i=0;iN;i+)xi=yi; return av; main() int i; double xN= 46,30,32,40,6,17,45,15,48,26; for(i=0;iN;i+)printf(“%4.0f“,xi); printf(“/n“); printf(“/nThe average is:%f/n“,fun(x); printf(“/nThe r

9、esult:/n“,fun(x); for(i=0;iN;i+)printf(“%5.0f“,xi); printf(“/n“): (分数:30.00)解析:s/N i+ -1 解析 填空 1:由原程序可知,av 代表的是平均值,而平均值的求法是所有数的总和除以数的个数,因而本空应该填写 s/N。 填空 2:y 数组代表暂时存放 x 数组,if(xiav)表达的是当 x 数组中的数大于平均值时,应该把这些大于平均值的数放在 y 数组的前半部分,因而此空应该填 yj+。 填空 3:此空表明当 xi不等于什么时,xi中的数要赋值给 y 数组,由题意可知此空只能填写-1。二、程序改错题(总题数:1,

10、分数:30.00)2.给定程序 MODI1.C 的功能是读入一个英文文本行,将其中每个单词的第一个字母改成大写,然后输出此文本行(这里的“单词”是指由空格隔开的字符串)。 例如,若输入 I am a student to take the examination., 则应输出 I Am A Student To Take The Examination.。 请改正程序中的错误,使程序能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序如下。 #includectype.h #includestring.h /*found*/ includest

11、dio.h /*found*/ void upfst(char p) int k=0; for(;*p;p+) if(k) if(*p=“)k=0; else if(*P!=“) k=1;*p=toupper(*p); main() char chrstr81; printf(“/nPlease enter an English text line:“); gets(chrstr); printf(“/n/nBefore changing:/n%s“,chrstr); upfst(chrstr); printf(“/nAfter changing:/n%s/n“,chrstr); (分数:30

12、00)解析:#includestdio.h void upfst(char*p) 解析 头文件引用 include 前要加#,主函数中 fun 函数的调用方式说明函数 fun的参数应为指针类型。三、程序设计题(总题数:1,分数:40.00)3.程序定义了 NN 的二维数组,并在主函数中赋值。请编写函数 fun,函数的功能是求出数组周边元索的平均值并作为函数值返给主函数中的 s。 例如:a 数组中的值为 (分数:40.00)_正确答案:()解析:double fun(int wN) int i,j,k=0; double av=0.0; for(i=0;iN;i+) for(j=0;jN;j+) if(i=0|i=N-1|j=0|j=N-1) av=av+wij; k+; return av/k; 解析 本题要求计算二维数组周边元素的平均值,for 循环语句控制循环过程,if 条件语句根据数组元素的下标判断该元素是否为二维数组的周边元素。 本题采用逐一判断的方式,周边元素的规律为下标中有一个是 0 或 N1,所以只要下标中有一个为 0 或N-1,那么它一定是周边元素。计算周边元素个数的方式是当给 av 累加一个值时,k 也加 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