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

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

1、国家二级 C语言机试(操作题)模拟试卷 464及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.下列给定程序中,函数 fun的功能是:把形参 a所指数组中的偶数按原顺序依次存放到 ao、a1、a2中,把奇数从数组中删除,偶数的个数通过函数值返回。 例如,若 a所指数组中的数据最初排列为:9、1、4、2、3、6、5、8、7,删除奇数后,a 所指数组中的数据为:4、2、6、8,返回值为 4。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #inc

2、lude stdioh #define N 9 int fun(int a,int r1) int i,j; j=0; for(i=0;i n;i+) /*found*/ if( 【1】 =0) /*found*/ 【2】 =ai;j+; /*found*/ return 【3】 ; main() int bN=9,1,4,2,3,6,5,8,7,i,n; printf(“/nThe original da ta:/n“); for(i=0;i N;i+) printf(“4 d“,bi); printf(“/n“); n=fun(b,N); printf(“/nThe number of e

3、ver1:d/n“,n); printf(“/nThe ever1:/n“); for(i=0;i n;i+) printf(“4 d“,bi); printf(“/n“); (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能是:按以下递归公式求函数的值。 (分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.规定输入的字符串中只包含字母和*号。请编写函数 fun,其功能是:使字符串中尾部的*号不多于 n个,若多于 n个,则删除多余的*号;若少于或等于 n个,则不做任何操作,字符串中间和前面的*号不删除。 例如,字符串中的内容为

4、A*BC*DEF*G*”,若 n的值为 4,删除后,字符串中的内容应为“*A* BC*DEF*G*”;若 n的值为 7,则字符串中的内容仍为“*A*BC*DEF*G*”。n 的值在主函数中输入。编写函数时,不得使用 C语言提供的字符串函数。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序:#include stdioh void fun(char*a,int n)main() char s81;int n; printf (“Enter a string:/n“); gets(s); printf(“E

5、nter n:“); scanf(“d“,&n); fun(s,n); printf(“The string after deleted:/n“); puts(s);(分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 464答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.下列给定程序中,函数 fun的功能是:把形参 a所指数组中的偶数按原顺序依次存放到 ao、a1、a2中,把奇数从数组中删除,偶数的个数通过函数值返回。 例如,若 a所指数组中的数据最初排列为:9、1、4、2、3、6、5、8、7,删除奇数后,a 所指数组中的数据为:4、2、

6、6、8,返回值为 4。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include stdioh #define N 9 int fun(int a,int r1) int i,j; j=0; for(i=0;i n;i+) /*found*/ if( 【1】 =0) /*found*/ 【2】 =ai;j+; /*found*/ return 【3】 ; main() int bN=9,1,4,2,3,6,5,8,7,i,n; printf(“/nThe original da ta

7、/n“); for(i=0;i N;i+) printf(“4 d“,bi); printf(“/n“); n=fun(b,N); printf(“/nThe number of ever1:d/n“,n); printf(“/nThe ever1:/n“); for(i=0;i n;i+) printf(“4 d“,bi); printf(“/n“); (分数:2.00)_正确答案:(正确答案:(1)ai2 (2)aj (3)j)解析:解析:本题考查:if 语句条件表达式;数组变量赋值;函数返回值。 填空 1:if语句条件表达式,判断数组元素是否为偶数,对 2求余,结果为 0,则为偶数;结

8、果为 1则为奇数。 填空 2:如果该数组元素是偶数,则将其值保存。 填空 3:最后按要求将偶数个数通过 return语句返回给 main函数。二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能是:按以下递归公式求函数的值。 (分数:2.00)_正确答案:(正确答案:(1)int fun (int n) (2)if(n=1)解析:解析:本题考查:有参函数定义;if 语句条件表达式中=与=的区别。 (1)定义有参函数时,形参变量要分别定义其类型,根据主函数中的调用函数可知,此处形参变量应定义为 int型。 (2)if 条件判断表达式中,n=1 是赋值表达式,表达式的

9、值永远为真,不能形成判断条件,应将 n=1改为 n =1。三、程序设计题(总题数:1,分数:2.00)3.规定输入的字符串中只包含字母和*号。请编写函数 fun,其功能是:使字符串中尾部的*号不多于 n个,若多于 n个,则删除多余的*号;若少于或等于 n个,则不做任何操作,字符串中间和前面的*号不删除。 例如,字符串中的内容为“*A*BC*DEF*G*”,若 n的值为 4,删除后,字符串中的内容应为“*A* BC*DEF*G*”;若 n的值为 7,则字符串中的内容仍为“*A*BC*DEF*G*”。n 的值在主函数中输入。编写函数时,不得使用 C语言提供的字符串函数。 注意:部分源程序给出如下。

10、 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序:#include stdioh void fun(char*a,int n)main() char s81;int n; printf (“Enter a string:/n“); gets(s); printf(“Enter n:“); scanf(“d“,&n); fun(s,n); printf(“The string after deleted:/n“); puts(s);(分数:2.00)_正确答案:(正确答案:void fun(char*a,int n) int i=0,k

11、0; char *p, *t; p=t=a; /*将指针移动到字符串末尾*/ while(*t) t+; t 一一; /*从后往前如果是*则使 k+,找到最后一个*所在的位置,并记录*的个数*/ while(*t=*) /*指针 t指向前一个,同时标量 k增加一*/ k+,t 一一,) /*如果最后*的个数大于允许的个数*/ if (kn) /*循环次数不大于前面的字符与最大允许*的个数之和*/ while(*p&p t+n+1) /*把字符保存到数组 a中*/ ai=*p; i+; p+; ai=/0; )解析:解析:本题考查:循环判断语句;字符串的操作。字符串中尾部*号不能多于 n个,多余的要删除。首先需要通过 while循环统计字符串尾部*号,然后通过 if条件语句完成尾部*号数和 n的比较,若尾部*号数多于 n个,则需要把 n个*号和其余字符重新保留。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 61754-9-2002 Fibre optic connector interfaces - Part 9 Type DS connector family (IEC 61754-9 1996 modified) German version EN 61754-9 2001《光纤连接器接口 第9部分 数据系列(DS)型连接器系列 (IEC 6.pdf DIN EN 61754-9-2002 Fibre optic connector interfaces - Part 9 Type DS connector family (IEC 61754-9 1996 modified) German version EN 61754-9 2001《光纤连接器接口 第9部分 数据系列(DS)型连接器系列 (IEC 6.pdf
  • DIN EN 61755-1 Berichtigung 1-2008 Fibre optic connector optical interfaces - Part 1 Optical interfaces for single mode non-dispersion shifted fibres - General and guidance (IEC 61.pdf DIN EN 61755-1 Berichtigung 1-2008 Fibre optic connector optical interfaces - Part 1 Optical interfaces for single mode non-dispersion shifted fibres - General and guidance (IEC 61.pdf
  • DIN EN 61755-1-2006 Fibre optic connector optical interfaces - Part 1 Optical interfaces for single mode non-dispersion shifted fibres - General and guidance (IEC 61755-1 2005) Ger.pdf DIN EN 61755-1-2006 Fibre optic connector optical interfaces - Part 1 Optical interfaces for single mode non-dispersion shifted fibres - General and guidance (IEC 61755-1 2005) Ger.pdf
  • DIN EN 61755-2-1-2007 Fibre optic connector optical interfaces - Part 2-1 Optical interface standard single mode non-angled physically contacting fibres (IEC 61755-2-1 2006) German.pdf DIN EN 61755-2-1-2007 Fibre optic connector optical interfaces - Part 2-1 Optical interface standard single mode non-angled physically contacting fibres (IEC 61755-2-1 2006) German.pdf
  • DIN EN 61755-2-2-2007 Fibre optic connector optical interfaces - Part 2-2 Optical interface standard single mode angled physically contacting fibres (IEC 61755-2-2 2006) German ver.pdf DIN EN 61755-2-2-2007 Fibre optic connector optical interfaces - Part 2-2 Optical interface standard single mode angled physically contacting fibres (IEC 61755-2-2 2006) German ver.pdf
  • DIN EN 61755-2-4-2015 Fibre optic interconnecting devices and passive components - Connector optical interfaces - Part 2-4 Connection parameters of non-dispersion shifted single-mo.pdf DIN EN 61755-2-4-2015 Fibre optic interconnecting devices and passive components - Connector optical interfaces - Part 2-4 Connection parameters of non-dispersion shifted single-mo.pdf
  • DIN EN 61755-2-5-2015 Fibre optic interconnecting devices and passive components - Connector optical interfaces - Part 2-5 Connection parameters of non-dispersion shifted single-mo.pdf DIN EN 61755-2-5-2015 Fibre optic interconnecting devices and passive components - Connector optical interfaces - Part 2-5 Connection parameters of non-dispersion shifted single-mo.pdf
  • DIN EN 61755-3-1-2009 Fibre optic connector optical interfaces - Part 3-1 Optical interface 2 5 mm and 1 25 mm diameter cylindrical full zirconia PC ferrule single mode fibre (IEC .pdf DIN EN 61755-3-1-2009 Fibre optic connector optical interfaces - Part 3-1 Optical interface 2 5 mm and 1 25 mm diameter cylindrical full zirconia PC ferrule single mode fibre (IEC .pdf
  • DIN EN 61755-3-10-2017 Fibre optic interconnecting devices and passive components - Connector optical interfaces - Part 3-10 Connector parameters of non-dispersion shifted single m.pdf DIN EN 61755-3-10-2017 Fibre optic interconnecting devices and passive components - Connector optical interfaces - Part 3-10 Connector parameters of non-dispersion shifted single m.pdf
  • 相关搜索

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

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