【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷315及答案解析.doc

上传人:registerpick115 文档编号:1332129 上传时间:2019-10-17 格式:DOC 页数:3 大小:31KB
下载 相关 举报
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷315及答案解析.doc_第1页
第1页 / 共3页
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷315及答案解析.doc_第2页
第2页 / 共3页
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷315及答案解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 315及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的作用是:不断从终端读入整数,由变量 a统计大于 0的个数,用变量 c来统计小于 0的个数,当输入 0时结束输入,并通过形参 pa和 pb把统计的数据传回主函数进行输出。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:源程序存放在BIANK1C 中。不得增行或删行,也不得更改程序的结构! 试题程序: #includestdioh void fun(int*px,int*PY) *found* in

2、t 【1】 ; scanf(“d“,k); *found* while 【2】 if(k0)a+; if(k0)b+; *found* 【3】 ; *px=a;*Py=b; main() int x,y; fun(x,y); printf(“x=d y=dn“,x,y); (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.已知一个数列从 0项开始的前 3项:0、0、1,以后的各项都是其相邻的前 3项之和。下列给定的程序中,函数 fun的功能是:计算并输出该数列前 n项的平方根之和 sum。n 的值通过形参传入。例如,当n=10时,程序的输出结果应为 23197745。请改正程

3、序中的错误,使它能得出正确的结果。注意:部分源程序在文件 MODI1C 中,不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includestdlibh#includeconioh#includestdioh#includemathh*found*fun(int n) double sum,s0,s1,s2,,s; int k; sum=10; if(n=2)sum=00 ; s0=00;s1=00;s2=10; for(k=4;k=n;k+) s=s0+s1+s2; sum+=sqrt(s); S0=s1;s1=s2;s2=S; *found* return sum

4、void main()int n; system(“CLS“); printf(“Input N=“); scanf(“d“,n); printf(“fn“,fun(n);(分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.编写函数 fun,其功能是:将两个两位数的正整数 a、b 合并成个整数放在 c中。合并的方式是:将a数的十位和个位数依次放在 c数的十位和千位上,b 数的十位和个位数依次放在 c数的百位和个位上。例如,当 a=45,b:12 时,调用该函数后,c=5142。注意:部分源程序给出如下。数据文件 INDAT 中的数据不得修改。请勿改动主函数 main和其他函数中

5、的任何内容,仅在函数 fun的花括号中填入编写的若干语句。试题程序:#includestdlibh#incluclestdioh#includeconiohvoid fun(int a,int b,long*c)void main() int a,b; long c ; system(“CLS“); printf(“Input a,b:“);scanf(“dd“,a,b); fun(a,b,c); printf(“The result is:ldn”,c);(分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 315答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:

6、1,分数:2.00)1.给定程序中,函数 fun的作用是:不断从终端读入整数,由变量 a统计大于 0的个数,用变量 c来统计小于 0的个数,当输入 0时结束输入,并通过形参 pa和 pb把统计的数据传回主函数进行输出。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:源程序存放在BIANK1C 中。不得增行或删行,也不得更改程序的结构! 试题程序: #includestdioh void fun(int*px,int*PY) *found* int 【1】 ; scanf(“d“,k); *found* while 【2】 if(k0)a+; if(k0)b+;

7、found* 【3】 ; *px=a;*Py=b; main() int x,y; fun(x,y); printf(“x=d y=dn“,x,y); (分数:2.00)_正确答案:(正确答案:(1)a=0,b=0,k (2)(k!=0) (3)scanf(“d“,&k)解析:解析:填空 1:下面的 scanf函数用到变量 k,需要提前定义,在 while循环中使用了临时存放正、负数个数的变量 a,b,因此也要提前定义。 填空 2:根据题意,输入 0时结束程序,因此当 k!=0时进入循环记录正负数的个数。 填空 3:需要不断从终端输人整数,因此在循环体内添加输入操作。二、程序修改题(总题数:

8、1,分数:2.00)2.已知一个数列从 0项开始的前 3项:0、0、1,以后的各项都是其相邻的前 3项之和。下列给定的程序中,函数 fun的功能是:计算并输出该数列前 n项的平方根之和 sum。n 的值通过形参传入。例如,当n=10时,程序的输出结果应为 23197745。请改正程序中的错误,使它能得出正确的结果。注意:部分源程序在文件 MODI1C 中,不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includestdlibh#includeconioh#includestdioh#includemathh*found*fun(int n) double sum,

9、s0,s1,s2,,s; int k; sum=10; if(n=2)sum=00 ; s0=00;s1=00;s2=10; for(k=4;k=n;k+) s=s0+s1+s2; sum+=sqrt(s); S0=s1;s1=s2;s2=S; *found* return sumvoid main()int n; system(“CLS“); printf(“Input N=“); scanf(“d“,n); printf(“fn“,fun(n);(分数:2.00)_正确答案:(正确答案:(1)double fun(int n) (2)return sum;)解析:解析:(1)根据函数的返回

10、值可知函数:fun 应定义为 double类型。 (2)语法错误,缺分号。三、程序设计题(总题数:1,分数:2.00)3.编写函数 fun,其功能是:将两个两位数的正整数 a、b 合并成个整数放在 c中。合并的方式是:将a数的十位和个位数依次放在 c数的十位和千位上,b 数的十位和个位数依次放在 c数的百位和个位上。例如,当 a=45,b:12 时,调用该函数后,c=5142。注意:部分源程序给出如下。数据文件 INDAT 中的数据不得修改。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入编写的若干语句。试题程序:#includestdlibh#inclucles

11、tdioh#includeconiohvoid fun(int a,int b,long*c)void main() int a,b; long c ; system(“CLS“); printf(“Input a,b:“);scanf(“dd“,a,b); fun(a,b,c); printf(“The result is:ldn”,c);(分数:2.00)_正确答案:(正确答案:void fun(int a,int b,long*c) *b10 获取 b的个位,a10 获取 a的十位,a10 获取 a的个位,b10 获取 b的十位* *c=b10+(a10)*10+(b10)*100+(a10)*1000; )解析:解析:本题主要的问题是如何取出 a和 b的个位数和十位数,取出后如何表示成 c中相应的位数。由于 a和 b都是只有两位的整数,所以分别对它们除 10可得到它们的十位数,分别用 10对它们求余可得到它们的个位数。得到后对应乘以 1000、100、10、1 即可得到 c的千位数、百位数、十位数和个位数。注意使用 c时要进行指针运算。

展开阅读全文
相关资源
猜你喜欢
  • EN 61753-131-3-2011 en Fibre optic interconnecting devices and passive components - Performance standard - Part 131-3 Single-mode mechanical fibre splice for category U - Uncontrol.pdf EN 61753-131-3-2011 en Fibre optic interconnecting devices and passive components - Performance standard - Part 131-3 Single-mode mechanical fibre splice for category U - Uncontrol.pdf
  • EN 61753-141-2-2011 en Fibre optic interconnecting devices and passive components - Performance standard - Part 141-2 Fibre optic passive chromatic dispersion compensator using sin.pdf EN 61753-141-2-2011 en Fibre optic interconnecting devices and passive components - Performance standard - Part 141-2 Fibre optic passive chromatic dispersion compensator using sin.pdf
  • EN 61753-143-2-2013 en Fibre optic interconnecting devices and passive components - Performance standard - Part 143-2 Optical passive VIPA-based dispersion compensator of single-mo.pdf EN 61753-143-2-2013 en Fibre optic interconnecting devices and passive components - Performance standard - Part 143-2 Optical passive VIPA-based dispersion compensator of single-mo.pdf
  • EN 61753-2-1-2000 en Fibre Optic Interconnecting Devices and Passive Components Performance Standard Part 2-1 Fibre Optic Connectors Terminated on Single-Mode Fibre For Category U .pdf EN 61753-2-1-2000 en Fibre Optic Interconnecting Devices and Passive Components Performance Standard Part 2-1 Fibre Optic Connectors Terminated on Single-Mode Fibre For Category U .pdf
  • EN 61753-2-3-2001 en Fibre Optic Interconnecting Devices and Passive Components Performance Standard - Part 2-3 Non-Connectorised Single Mode 1xN and 2xN Non-Wavelength-Selective B.pdf EN 61753-2-3-2001 en Fibre Optic Interconnecting Devices and Passive Components Performance Standard - Part 2-3 Non-Connectorised Single Mode 1xN and 2xN Non-Wavelength-Selective B.pdf
  • EN 61753-381-2-2016 en Fibre optic interconnecting devices and passive components - Performance standard - Part 381-2 Cyclic arrayed waveguide grating - Category C (controlled envi.pdf EN 61753-381-2-2016 en Fibre optic interconnecting devices and passive components - Performance standard - Part 381-2 Cyclic arrayed waveguide grating - Category C (controlled envi.pdf
  • EN 61753-381-6-2016 en Fibre optic interconnecting devices and passive components - Performance standard - Part 381-6 Cyclic arrayed waveguide grating - Category O (uncontrolled en.pdf EN 61753-381-6-2016 en Fibre optic interconnecting devices and passive components - Performance standard - Part 381-6 Cyclic arrayed waveguide grating - Category O (uncontrolled en.pdf
  • EN 61753-382-2-2016 en Fibre optic interconnecting devices and passive components - Performance standard - Part 382-2 Non-connectorized singlemode bidirectional G-PON-NGA WWDM devi.pdf EN 61753-382-2-2016 en Fibre optic interconnecting devices and passive components - Performance standard - Part 382-2 Non-connectorized singlemode bidirectional G-PON-NGA WWDM devi.pdf
  • EN 61754-1-2013 en Fibre optic interconnecting devices and passive components - Fibre optic connector interfaces - Part 1 General and guidance.pdf EN 61754-1-2013 en Fibre optic interconnecting devices and passive components - Fibre optic connector interfaces - Part 1 General and guidance.pdf
  • 相关搜索

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

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