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

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

1、国家二级( C语言)机试模拟试卷 375及答案与解析 一、程序填空题( 30分) 1 给定程序中,函数 fun的功能是:将形参 n中,各位上为偶数的数取出,并按原来从高位到低位的顺序组成一个新的数,并作为函数值返回。 例如,从主函数输入一个整数: 27638496,函数返回值为: 26846。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANKl C中。 不得增行或删行,也不得更改程序的结构 ! #include unsigned long fun(unsigned long n) unsigned long x=0, s, i

2、 int t; s=n; *found* i= 【 1】; *found* while(【 2】 ) t=s 10; if(t 2=0) *found* x=x+t*i; i=【 3】; s=s 10; return x; main() unsigned long n=一 1; while(n99999999 | n void fun(char p1, char p2) main() char s180, s240; void NONO(); printf(“Enter s1 and s2: n“); Scarlf(“ s s“, s1, s2); printf(“s1= s n“, s1)

3、 printf(“s2= s n“, s2); printf(“Invoke fun(s1, s2): n“); fun(s1, s2); printf(“After invoking: n“); printf(“ s n“, s1); NONO(); void NONO() *本函数用于打开文件,输入测试数据,调 用 fun函数,输出数据,关闭文件。 * int i; FTLE*rf, *wf ; char s180, s240; rf=fopen(“in dat“, “r“); wf=fopen(“out dat“, “w“); for(i=0; i10 ; i+) fscanf(rf,

4、 “ s“, s1); fscanf(rf, “ s“, s2); fun(s1, s2); fprintf(wf, “ s n“, s1); fclose(rf); fclose(wf); 国家二级( C语言)机试模拟试卷 375答案与解析 一、程序填空题( 30分) 1 【正确答案】 (1)1 (2)s (3)i*10 【试题解析】 第一 空:由 “if(t 2=0)x=x+-t*i; i=【 3】; “可知,如果 t是偶数,那么 t添加到返回值里面,比如第一次得到 t=2,那么 x=0+2*l;下一次得到了 t=4,那么此时 x的值应该是 2+2*10;再下一次得到 t=2,那么 x=2

5、2+2*100,即 x的值是在上一次值的基础上加上新得到的值乘以其权值,因此 i是代表权值。第一空处是初始化 i,第一次进入 if语句时, x是个 1位数,此时权值 i应为 1,做第一空处应为 “1“, 第二空:第二空处是填循环的终止条件,在循环体内, s每次缩小 10倍,在最后一次进入循环的 时候, s是一个一位数, s 10之后 s变成 0,下次就不应该进入while循环,因此 while循环的终止条件是 s不为 0,故第二空处为 “s“或 “s!=0“。 第三空:由第一空的分析可知权值 i是在上一次的基础上增加 10倍,故第三空处应为 “i*10“。 二、程序修改题( 30分) 2 【正确答案】 (1)错误: int j=1 正确: double j=1.0; (2)错误: y+=1/(i*i); 正确: y+=j/(i*i); 【试题解析】 错误 1:为了做后面的除法运算, j要定义为 实型数,否则除得的结果将为整数。错误 2:题中公式是加减相间的运算,通过来实现。 三、程序设计题( 40分) 3 【正确答案】 char*p=p1; while(*p)p+; while(*p2) *p+= p2+; *p=0; 【试题解析】 (1)先求出串 1的元素个数。 (2)然后把串 2的元素放到串 l最后的位置,依次把串 2中的所有字符全部放到串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