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

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

1、国家二级 C语言机试(操作题)模拟试卷 498及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是:将 NxN矩阵主对角线元素中的值与反向对角线对应位置上元素中的值进行交换。例如,若 N=3,有下列矩阵: 1 2 3 4 5 6 7 8 9 交换后为: 3 2 1 4 5 6 9 8 7 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1C 中。 不得增行或删行,也不得更改程序的结构! #include #define N 4 /* found*/

2、void fun (int【1】, int n) int i,s; /* found*/ for(【2】; i+) s=tii; ti i=ti n-i-1; /*found*/ ti n-l-i=【3】; main () int tN=21,12,13,24,25, 16,47,38,29,11,32,54,42, 21,33,10,i,j; printf(“/nThe original array:/n“); for(i=0; i_二、程序修改题(总题数:1,分数:2.00)2.由 N个有序整数组成的数列己放在一维数组中,给定程序 MODI1C 中函数 fun的功能是:利用折半查找算法查找

3、整数 m在数组中的位置。若找到,返回其下标值;反之,返回-1。 折半查找的基本算法是:每次查找前先确定数组中待查的范围:low 和 high(lowhigh,查找结束。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。 #include #define N 10 /* found* / void fun(int a, int m) int low=0,high=N-l,mid; while (lowamid)解析:解析:(1)根据主函数中“k=fun(a,m);”,知道函数 fun应该是返回 int型的函数,所以第一个标识下面定义的

4、void fun(int a,int m)”应该改为“intfun(int a,int m)”。 (2)第二个标识下的“else If(mamid)”是判断 m是否比 amid大,在 while循环中采用的是 if-elseif-else语句,显然“else If,当中“If”应当小写,故第二标识下“else If(mamid)”应改为“elseif(mamid)”。三、程序设计题(总题数:1,分数:2.00)3.假定输入的字符串中只包含字母和*号。请编写函数 fun,它的功能是:除了尾部的*号之外,将字符串中其他*号全部删除。形参 p已指向字符串中最后的一个字母。在编写函数时,不得使用 C

5、语言提供的字符串函数。 例如, 字符串中的内容为:*A*BC*DEF*G*,删除后,字符串中的内容应当是:ABCDEFG*。 注意:部分源程序在文件 PROG1C 中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。#include stdio.hvoid fun(char *a, char *p)main () char s81,*t;void NONO ();printf(“Enter a string:/n“);gets (s);t=s;while(*t)t+;t-;while(*t=*)t-;fun(s , t);printf(“The

6、 string after deleted: /n“);puts (s); NONO();void NONO() *本函数用于打开文件,输入数据,调 用函数,输出数据,关闭文件。 *FILE *in, *out ; int i ; char s81,*t ; in = fopen(“in.dat“,“r“); out = fopen(“out.dat“,“w“); for(i = 0 ; i 10 ; i+) fscanf(in, “%s“, s);t=s;while(*t)t+;t-;while (*t=*) t-;fun(s,t);fprintf(out, “%s/n“, s) ;fclo

7、se(in);fclose(out); (分数:2.00)_正确答案:(正确答案:char *q=a; int j=0; while(*q&q解析:解析:(1)首先,主函数中使指针移到字符串的最后一个字符,对字符串由串尾开始进行操作。 (2)然后,指针由尾开始向头移动,查找第一个非“*”号字符,指针 t指向后一个非“*”,即从最后一个非“*”,字符开始的字符都不需要删除,将前面的其他“*”号全部删除后,将尾部的“*”字符往前移动即可。 (3)确定了字符数组的最后一个字符非“*”后,调用 fun函数,在 fun函数中,将原串中由起始位置的字符开始到最后一个非“*”逐个查询该字符是否是“*”字符,如果是则删除,并将后面的字符往前移动;然后将 t之后的字符移动到前面,最后在字符串的后面添加“/0”即可。

展开阅读全文
相关资源
猜你喜欢
  • BS EN 525-2009 Non-domestic direct gas-fired forced convection air heaters for space heating not exceeding a net heat input of 300 kW《空间加热用净热输入不超过300 kW的非家用直接燃气式强制对流空气加热器》.pdf BS EN 525-2009 Non-domestic direct gas-fired forced convection air heaters for space heating not exceeding a net heat input of 300 kW《空间加热用净热输入不超过300 kW的非家用直接燃气式强制对流空气加热器》.pdf
  • BS EN 526-1995 Inland navigation vessels - Gangways with a length not exceeding 8 m Requirements types《内河航行船舶 长度不超过8m的跳板 要求和类型》.pdf BS EN 526-1995 Inland navigation vessels - Gangways with a length not exceeding 8 m Requirements types《内河航行船舶 长度不超过8m的跳板 要求和类型》.pdf
  • BS EN 527-1-2011 Office furniture Work tables and desks Dimensions《办公家具 工作台及桌子 尺寸规格》.pdf BS EN 527-1-2011 Office furniture Work tables and desks Dimensions《办公家具 工作台及桌子 尺寸规格》.pdf
  • BS EN 527-2-2016 Office furniture Work tables Safety strength and durability requirements《办公家具 工作台 第2部分 安全性、强度和耐久性要求》.pdf BS EN 527-2-2016 Office furniture Work tables Safety strength and durability requirements《办公家具 工作台 第2部分 安全性、强度和耐久性要求》.pdf
  • BS EN 527-3-2003 Office furniture - Work tables and desks - Methods of test for the determination of the stability and the mechanical strength of the structure《办公家具 工作台和写字台 结构的稳定性和.pdf BS EN 527-3-2003 Office furniture - Work tables and desks - Methods of test for the determination of the stability and the mechanical strength of the structure《办公家具 工作台和写字台 结构的稳定性和.pdf
  • BS EN 528-2008 Rail dependent storage and retrieval equipment - Safety requirements《轨道式存储和卸取设备 安全性要求》.pdf BS EN 528-2008 Rail dependent storage and retrieval equipment - Safety requirements《轨道式存储和卸取设备 安全性要求》.pdf
  • BS EN 529-2005 Respiratory protective devices - Recommendations for selection use care and maintenance - Guidance document《呼吸保护装置 选择、使用、保养和维修的建议 指导性文件》.pdf BS EN 529-2005 Respiratory protective devices - Recommendations for selection use care and maintenance - Guidance document《呼吸保护装置 选择、使用、保养和维修的建议 指导性文件》.pdf
  • BS EN 530-2010 Abrasion resistance of protective clothing material Test methods《防护服材料的耐磨性能 试验方法》.pdf BS EN 530-2010 Abrasion resistance of protective clothing material Test methods《防护服材料的耐磨性能 试验方法》.pdf
  • BS EN 536-2015 Road construction machines Mixing plants for road construction materials Safety requirements《道路施工机械 道路施工材料用混合设备 安全要求》.pdf BS EN 536-2015 Road construction machines Mixing plants for road construction materials Safety requirements《道路施工机械 道路施工材料用混合设备 安全要求》.pdf
  • 相关搜索

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

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