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

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

1、国家二级( C语言)机试模拟试卷 179及答案与解析 一、程序填空题( 30分) 1 函数 fun的功能是:逆置数组元素中的值。例如:若 a所指数组中的数据依次为: 1、 2、 3、 4、 5、 6、 7、 8、 9,则逆置后依次为: 9、 8、 7、 6、 5、 4、 3、 2、1。形参 n给出数组中数据的个数。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANKl C中。 不得增行或删行,也不得更改程序的结构 ! #include void fun(int a, int n) int i, t; *found* for(i=

2、0; i void fun(10ng s, long*t) int d; long s1=1; *found* t=0; while(s0) d=s 10; *found* if(d 2=0) *t=d*s1+*t; s1 *=10; s/=10; main() long s, t; printf(“ nPlease enter s: “); scanf (“ id“, main()int n; double s; void NONO (); printf(“nPlease enter N:“); scanf(“%d“, s = fun(n); printf(“the result is: %

3、fn“, s); NONO();void NONO ()/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *fp, *wf ; int i, n ; double s; fp = fopen(“in.dat“,“r“); wf = fopen(“out.dat“,“w“); for(i = 0 ; i 10 ; i+) fscanf(fp, “%d“, s = fun(n); fprintf(wf, “%fn“, s); fclose(fp); fclose(wf); 国家二级( C语言)机试模拟试卷 179答案与解析 一、程序填空题( 30分) 1 【正确答

4、案】 n/2 i an-i-1 【试题解析】 第一空:由审题分析可知,总共交换 n/2次,故循环的终止条件为i等于 n/2,故第一空处应为 “n/2”。 第二空: a0和 an-1交换, a1和 an-2交换 ,因此 ai和 an-i-1交换,故第二空处应为 “i”。 第三空: “t=ai; ai=an-1-i;”所以第三空处是把 t值赋值 an-1-i,故第三空处应为 “an-1-i”。 二、程序修改题( 30分) 2 【正确答案】 (1)*t=0; (2)if(d 2 !=0) 【试题解析】 (1)第一个错误标识下的 “t=0“语句中的 t,根据 fun函数定义 “void fun(10n

5、g s, long*t)“,它应该是个长整型的指针变量,所以 “t=0“语句中的 t只能取地址值,而不能取长整数,因此 “t=0; “改为 “*t=0; “。 (2)判断 d是否为奇数,即判断 “d 21=0“;而 “d 2=0“是判断 d是否偶数的方法 ,因此第二个标识下 “if(d 2=0)“改为 “if(d 21; 0)“。 三、程序设计题( 40分) 3 【正确答案】 int k; float str=1.0,sum=1.0; for(k=2;k=n;k+) sum=sum+k; /求得每一项的分母 str=str+1/sum; /级数累加求和 【试题解析】 进入 fun函数,根据前面的分析: 首先,求得每一项分母的值 sum,即利用上一项来表示 “sum=sum+k;”。 然后,对每一项进行累加 “str=str+1/sum;”。 最后,返回运算结果 “str”。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO CIE 19476-2014 Characterization of the performance of illuminance meters and luminance meters《照度计和亮度计的性能特征》.pdf BS ISO CIE 19476-2014 Characterization of the performance of illuminance meters and luminance meters《照度计和亮度计的性能特征》.pdf
  • BS ISO CIE 28077-2016 Photocarcinogenesis action spectrum (non-melanoma skin cancers)《光致癌作用光谱(非黑素瘤皮肤癌)》.pdf BS ISO CIE 28077-2016 Photocarcinogenesis action spectrum (non-melanoma skin cancers)《光致癌作用光谱(非黑素瘤皮肤癌)》.pdf
  • BS ISO IEC 10026-4-1995 Information technology - Open systems interconnection - Distributed transaction processing - Protocol Implementation Conformance Statement (PICS) p.pdf BS ISO IEC 10026-4-1995 Information technology - Open systems interconnection - Distributed transaction processing - Protocol Implementation Conformance Statement (PICS) p.pdf
  • BS ISO IEC 10026-6-1995 Information technology - Open systems interconnection - Distributed transaction processing - Unstructured data transfer《信息技术 开放式系统互连 分布式执行处理 非结构数据传.pdf BS ISO IEC 10026-6-1995 Information technology - Open systems interconnection - Distributed transaction processing - Unstructured data transfer《信息技术 开放式系统互连 分布式执行处理 非结构数据传.pdf
  • BS ISO IEC 10030-1995 Information technology - Telecommunications and information exchange between systems - End System Routeing Information Exchange protocol for use in c.pdf BS ISO IEC 10030-1995 Information technology - Telecommunications and information exchange between systems - End System Routeing Information Exchange protocol for use in c.pdf
  • BS ISO IEC 10040-1993 Information technology - Open systems interconnection - Systems management overview《信息技术 开放式系统互连 系统管理综述》.pdf BS ISO IEC 10040-1993 Information technology - Open systems interconnection - Systems management overview《信息技术 开放式系统互连 系统管理综述》.pdf
  • BS ISO IEC 10089-1991 Information technology - 130 mm rewritable optical disk cartridge for information interchange《信息技术 信息交换用130mm可重写光盘盒》.pdf BS ISO IEC 10089-1991 Information technology - 130 mm rewritable optical disk cartridge for information interchange《信息技术 信息交换用130mm可重写光盘盒》.pdf
  • BS ISO IEC 10090-1993 Information technology - 90 mm optical disk cartridges rewritable and read only for data interchange《信息技术 数据交换用可重写和只读90mm盒式光盘》.pdf BS ISO IEC 10090-1993 Information technology - 90 mm optical disk cartridges rewritable and read only for data interchange《信息技术 数据交换用可重写和只读90mm盒式光盘》.pdf
  • BS ISO IEC 10116-2017 Information technology Security techniques Modes of operation for an n-bit block cipher《信息技术 安全技术 n位块密码算法的操作方式》.pdf BS ISO IEC 10116-2017 Information technology Security techniques Modes of operation for an n-bit block cipher《信息技术 安全技术 n位块密码算法的操作方式》.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1