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

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

1、国家二级 C语言机试(操作题)模拟试卷 475及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是: 统计形参 s所指的字符串中数字字符出现的次数,并存放在形参 t所指的变量中,最后在主函数中输出。 例如,若形参 s所指的字符串为“abcdef35adgh3kjsdf7”,则输出结果为 4。 请在程序的下画线处填入正确内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include stdioh void fun(char*s,int*t)

2、int i,n; n=0; /*found*/ for(i=0; 【1】 !=0;i+) /*found*/ if(si =0&si 【2】 ) n+; /*found*/ 【3】 ; main() char s80=“abcdef35adih3kjsdf7“; int t; printf(“/nThe original string is:s/n“,s); fun(s,&t); printf(“/nThe result is:d/n“,t); (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中函数 fun的功能是:通过某种方式实现两个变量值的交换,规定不允许增

3、加语句和表达式。 例如,变量 a中的值原为 8,b 中的值原为 3,程序运行后 a中的值为 3,b 中的值为 8。 请改正程序中的错误,使它得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构! 试题程序:#include stdlibh #include conioh #inclucle stdioh int fun(int*x,int y) int t;/*found*/ t=x;x=y;/*found*/ return(y)=void main() int a=3,b=8; system(“CLS“); printf(“dd/n“,a,b); b=fun(

4、a,b); printf(“dd/n“,a,b);(分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.编写函数 fun,其功能是:求出 1 1000 之间能被 7或 1 1整除,但不能同时被 7和 1 1整除的所有整数,并将其放在 a所指的数组中,通过 n返回这些数的个数。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序:#include stcllibh #include conioh #include stdioh void fun(int*a,int*n)void main() in

5、t aa1 0 00,n,k; system(“CLS“); fun(aa,&n); for(k=0;k n;k+) if(k+1)1 0=0) (printf(“5 d“,aak); printf(“/n“);/*一行写 9个数*/ else pr2ntf(“5 d“,aak);(分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 475答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是: 统计形参 s所指的字符串中数字字符出现的次数,并存放在形参 t所指的变量中,最后在主函数中输出。 例如,若形参 s所指的

6、字符串为“abcdef35adgh3kjsdf7”,则输出结果为 4。 请在程序的下画线处填入正确内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include stdioh void fun(char*s,int*t) int i,n; n=0; /*found*/ for(i=0; 【1】 !=0;i+) /*found*/ if(si =0&si 【2】 ) n+; /*found*/ 【3】 ; main() char s80=“abcdef35adih3kjsdf7“; int t; printf(“/nT

7、he original string is:s/n“,s); fun(s,&t); printf(“/nThe result is:d/n“,t); (分数:2.00)_正确答案:(正确答案:(1)si (2)9 (3)*t=n)解析:解析:本题考查:for 循环语句;if 语句条件表达式;指针变量。 填空 1:通过 for循环语句来判断是否到字符型结尾,变量 i用来存放字符型数组下标,则应填入 s i。 填空 2:题目要求判断数字字符,所以此处应填入9。 填空 3:将数字字符个数存入变量 t中,此处需注意变量 t是指针变量。 if语句的条件表达式一般会考查三方面的内容: (1)条件判断,即

8、与 =、 与 =、=与!=的区别,需要仔细分析题干的意思,确定条件表达式的内容。 (2)逻辑判断,即&(逻辑与)与|(逻辑或)的区别,需要根据题干确定 if条件中若干个条件表达式的并存关系。 (3)=(赋值号)与=(等于号)的区别,注意在 if条件中不会出现=(赋值号)。二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中函数 fun的功能是:通过某种方式实现两个变量值的交换,规定不允许增加语句和表达式。 例如,变量 a中的值原为 8,b 中的值原为 3,程序运行后 a中的值为 3,b 中的值为 8。 请改正程序中的错误,使它得出正确的结果。 注意:不要改动 main函数,不得增行或

9、删行,也不得更改程序的结构! 试题程序:#include stdlibh #include conioh #inclucle stdioh int fun(int*x,int y) int t;/*found*/ t=x;x=y;/*found*/ return(y)=void main() int a=3,b=8; system(“CLS“); printf(“dd/n“,a,b); b=fun(&a,b); printf(“dd/n“,a,b);(分数:2.00)_正确答案:(正确答案:(1)t=*x;*x=y; (2)return(t);或 retum t;)解析:解析:本题考查:指针型

10、变量的使用;通过 return语句完成函数值的返回。 首先,定义变量 t作为中间变量,然后进行数据交换,注意参数 x是指针变量,交换时应使用*x,最后确定返回值;根据代码b= fun(8a,b),可以知道返回值将赋给变量 b,而 b中应存放交换前*x 中的值,所以函数应返回变量t。三、程序设计题(总题数:1,分数:2.00)3.编写函数 fun,其功能是:求出 1 1000 之间能被 7或 1 1整除,但不能同时被 7和 1 1整除的所有整数,并将其放在 a所指的数组中,通过 n返回这些数的个数。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花

11、括号中填入你编写的若干语句。 试题程序:#include stcllibh #include conioh #include stdioh void fun(int*a,int*n)void main() int aa1 0 00,n,k; system(“CLS“); fun(aa,&n); for(k=0;k n;k+) if(k+1)1 0=0) (printf(“5 d“,aak); printf(“/n“);/*一行写 9个数*/ else pr2ntf(“5 d“,aak);(分数:2.00)_正确答案:(正确答案:void fun (int*a,int *n) int i,j =

12、0; for(i=1;1 =1000;1+) /*求 1到 1000之内能被 7或 11整除但不能同时被 7和 11整除的所有整 数,并放入数组 a中*/ if( (17 一=0 |i 11 =0) &177!=0) aj+=i; *n=j; /*传回满足条件的数的个数*/ )解析:解析:本题考查:if 语句,用来判断能被 7整除或者能被 11整除,但又不能同时被 7和 11整除的数,此处需充分理解“逻辑与”和“逻辑或”的区别;for 循环语句的循环条件用来控制循环变量取值范围。 该题需要运用循环判断结构来实现,其中循环语句比较容易,只要确定循环变量的范围即可,下面来看判断语句。题目要求找出能被 7或 11整除,但不能同时被 7和 11整除的所有整数,能同时被 7和 11整除的整数一定能被 77整除,且不能被 77整除的数不一定就是能被 7或 11整除的数,因而,可得出程序中的 if语句。注意(j7 =01 1111 =0)两边必须要有小括号。

展开阅读全文
相关资源
猜你喜欢
  • SN T 3600-2013 Determination of residual monomers and other volatile low-molecular-mass compounds in raw rubber Dynamic headspace-gas chromatography method《生胶中残.pdf SN T 3600-2013 Determination of residual monomers and other volatile low-molecular-mass compounds in raw rubber Dynamic headspace-gas chromatography method《生胶中残.pdf
  • SN T 3601-2013 Determination of total sulfur in graphite Infrared absorption spectrometry《石墨中全硫含量的测定 红外吸收光谱法》.pdf SN T 3601-2013 Determination of total sulfur in graphite Infrared absorption spectrometry《石墨中全硫含量的测定 红外吸收光谱法》.pdf
  • SN T 3602-2013 Determination of organic oxygenate compounds in naphtha Gas chromatography《石脑油中有机含氧化合物的测定 气相色谱法》.pdf SN T 3602-2013 Determination of organic oxygenate compounds in naphtha Gas chromatography《石脑油中有机含氧化合物的测定 气相色谱法》.pdf
  • SN T 3603-2013 Quantitative screening of anthracene oil in rubber products Gas chromatography-mass spectrometry method《橡胶制品中蒽油的快速筛选测定 气相色谱-质谱联用法》.pdf SN T 3603-2013 Quantitative screening of anthracene oil in rubber products Gas chromatography-mass spectrometry method《橡胶制品中蒽油的快速筛选测定 气相色谱-质谱联用法》.pdf
  • SN T 3604-2013 Determination of copper silicon manganese zinc aluminum and iron in zinc concentrate ore X-ray fluorescence spectrometry《锌精矿中铜、硅、镁、锌、铝、铁含量的测定 X射线.pdf SN T 3604-2013 Determination of copper silicon manganese zinc aluminum and iron in zinc concentrate ore X-ray fluorescence spectrometry《锌精矿中铜、硅、镁、锌、铝、铁含量的测定 X射线.pdf
  • SN T 3605-2013 Determination of mercury content in liquid petroleum products Direct injection method《液体石油产品汞含量的测定 直接进样法》.pdf SN T 3605-2013 Determination of mercury content in liquid petroleum products Direct injection method《液体石油产品汞含量的测定 直接进样法》.pdf
  • SN T 3606-2013 Determination of water and sediment in middle distillate fuels Centrifuge method《中间馏分燃料中水和沉淀物含量的测定 离心法》.pdf SN T 3606-2013 Determination of water and sediment in middle distillate fuels Centrifuge method《中间馏分燃料中水和沉淀物含量的测定 离心法》.pdf
  • SN T 3607-2013 Determination of volatile nitrosamines in cosmetics Gas chromatography-tandem mass spectrometry method《化妆品中挥发性亚硝胺的测定 气相色谱-质谱 质谱法》.pdf SN T 3607-2013 Determination of volatile nitrosamines in cosmetics Gas chromatography-tandem mass spectrometry method《化妆品中挥发性亚硝胺的测定 气相色谱-质谱 质谱法》.pdf
  • SN T 3608-2013 Determination of fluorine in import and export cosmetics Ion chromatographic method《进出口化妆品中氟的测定 离子色谱法》.pdf SN T 3608-2013 Determination of fluorine in import and export cosmetics Ion chromatographic method《进出口化妆品中氟的测定 离子色谱法》.pdf
  • 相关搜索

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

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