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

上传人:jobexamine331 文档编号:498399 上传时间:2018-11-29 格式:DOC 页数:7 大小:31.50KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷448及答案与解析.doc_第1页
第1页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷448及答案与解析.doc_第2页
第2页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷448及答案与解析.doc_第3页
第3页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷448及答案与解析.doc_第4页
第4页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷448及答案与解析.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 448及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是将带头结点的单向链表逆置,即若原链表中从头至尾结点数据域依次为 2、 4、 6、 8、 10,逆置后,从头至尾结点数据域依次为10、 8、 6、 4、 2。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #include stdlib h #define N 5 typedef struct node int data; struct node

2、next; NODE; void fun(NODE*h) NODE *P, *q, *r; /*found*/ p=h一 【 1】 ; /*found*/ if(p=【 2】 )return; q=p一 next; p一 next =NULL; while(q) r=q一 next; q一 next=p; /*found*/ p=q; q=【 3】 ; h一 next=P; NODE*creatlist(int a) NODE*h, *p, *q; int i; h=(NODE*)malloc(sizeof(NODE); h一 next=NULL; for(i=0; i N; i+) q=(

3、NODE*)malloc(sizeof (NODE); q一 data=ai, q一 next=NULL; if(h一 next=NULL) h一 next=p=q; elsep一 next=q; p=q; ) return h; void outlist(NODE*h) NODE*p; P=h一 next; if(P=NULL) printf(“The list is NULL!n“); elSe printi(“nttead“); do fprintf(“一 d“, p一 data); p=p一 next; ) while(P!=NULL); printf(“一 Endn“); main

4、) NODE *head; int aN = 2,4,6,8 , 10 ; head = creatlist (a) ; printf ( “ nThe original outlist (head) ; fun (head) ; printf ( “nThe list after inverting :n“); outlist (head) ; 二、程序修改题 2 下列给定程序中,函数 fun的功能是:计算 s所指字符串中含有 t所指字符串的数目,并作为函数值返回。 请改正程序中的错误或在下画线处填上正确的内容并把下画线删除,使它能得出正确的结果。 注意:不要改动 maln函数,不得增行或

5、删行,也不得更改程序的结构! 试题程序 : #include stdlib h #include conio h #include string h #include stdio h #de fine N 80 int fun (char * s, char * t) int n; char *p, * r; n =0; /*found*/ *r=t; while ( *s ) p =s; while (*r ) if(*r=*p) r +, p + ; else break; if(*r=0) n + f /*found*/ 1 ; s + ; return n; void main ()

6、char aN,bN; int m; printf (“nPlease enter string a: “) ; gets (a) ; printf ( “ nPlease enter substring gets (b) ; m = fun (a,b) ; printf(“nThe result is :m 一 三、程序设计题 3 请编写函数 fun,其功能是:将放在字符串数组中的 M个字符串 (每串的长度不超过 N),按顺序合并组成一个新的字符串。 例如,若字符串数组中的 M个字符串为 “AAAA”, “BBBBBBB”, “CC”,则合并后 的字符串内容应该是 “AAAABBBBBBBC

7、C”。 注意:部分源程序给出如下。 请勿改动主函数 maln和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio h #include conio h #de fine M 3 #define N 20 void fun (char aMN,char *b) void main() char WMN=“AAAA“, “BBBBBBB“, “CC“); char a100: “#“); int i; printf(“The string: n“); for(i=0; i M; i+) puts(wi); printf(“n“); fu

8、n(w, a); printf(“The A string: n“); printf(“ s“, a); printf(“nn“); 国家二级 C语言机试(操作题)模拟试卷 448答案与解析 一 、程序填空题 1 【正确答案】 (1)next (2)NULL (3)r 【试题解析】 填空 1:本空考查了为 p赋初值,根据题目的要求是将带头结点的单向链表逆置可知, p的初值应该为 h一 next。 填空 2:if判断语句表明当 p等于什么时就要返回,因此只能当 p等于 NULL时返回,不用做后面的链表的逆置了。 填空 3:把 q的指针向后移动,才能实现将带头结点的单向链表逆置。因此本空填写 r。

9、 二、程序修改题 2 【正确答案】 (1)r=t; (2)r=t;或 r=&t0; 【试题解析】 从字符 串 s中找出子字符串的方法是:从第一个字符开始,对字符串进行遍历,若 s串的当前字符等于 t串的第一个字符,两字符串的指针自动加1,继续比较下一个字符;若比较至字符串 t的末尾,则跳出循环;若 s串的字符与 t串的字符不对应相同,则继续对 s串的下一个字符进行处理。 三、程序设计题 3 【正确答案】 void fun (char aM N,char *b) int i,j,k=0; for(i=0; i M; i+)/* 将字符串数组中的 M个字符串,按顺序存入一个新的字符串 */ for(j =0; aij!=0; j+) bk+=aij; bk=0; /*在字符串最后加上字符串结束标记符 */ 【试题解析】 本题考查:字符串连接操作。本程序中第 1个 for循环的作用是对二维数组行的控制,第 2个循环的作用是从同一行中取出字符并存放到一维数组 b中,语句是 bk+=aij;。

展开阅读全文
相关资源
猜你喜欢
  • ASHRAE NA-04-7-4-2004 Controlled Clean Operating Room Area《洁净操作室面积控制》.pdf ASHRAE NA-04-7-4-2004 Controlled Clean Operating Room Area《洁净操作室面积控制》.pdf
  • ASHRAE NA-04-8-1-2004 Evaluation of Moisture Buffer Effects by Performing Whole-Building Simulations《整体建筑模拟的水分缓冲效果的表演的评价》.pdf ASHRAE NA-04-8-1-2004 Evaluation of Moisture Buffer Effects by Performing Whole-Building Simulations《整体建筑模拟的水分缓冲效果的表演的评价》.pdf
  • ASHRAE NA-04-8-2-2004 Effect of Moisture on Hygrothermal and Energy Performance of a Building with Cellular Concrete Walls in Climatic Conditions of Poland《在波兰的气候条件下 一个建筑物蜂窝混凝土墙的水分.pdf ASHRAE NA-04-8-2-2004 Effect of Moisture on Hygrothermal and Energy Performance of a Building with Cellular Concrete Walls in Climatic Conditions of Poland《在波兰的气候条件下 一个建筑物蜂窝混凝土墙的水分.pdf
  • ASHRAE NA-04-8-2004 Symposium on Modeling Moisture Sorption Desorption by Building Matierials《建模水分吸着 解吸建设材料的研讨会上》.pdf ASHRAE NA-04-8-2004 Symposium on Modeling Moisture Sorption Desorption by Building Matierials《建模水分吸着 解吸建设材料的研讨会上》.pdf
  • ASHRAE NA-04-8-3-2004 Moderating Indoor Conditions with Hygroscopic Building Materials and Outdoor Ventilation《吸湿建材及户外通风对室内条件缓和》.pdf ASHRAE NA-04-8-3-2004 Moderating Indoor Conditions with Hygroscopic Building Materials and Outdoor Ventilation《吸湿建材及户外通风对室内条件缓和》.pdf
  • ASHRAE NA-04-8-4-2004 Predicting Indoor Temperature and Humidity Conditions Including Hygrothermal Interactions with the Building Envelope《室内温度和湿度条件的预测 包括湿热互动与建筑围护结构》.pdf ASHRAE NA-04-8-4-2004 Predicting Indoor Temperature and Humidity Conditions Including Hygrothermal Interactions with the Building Envelope《室内温度和湿度条件的预测 包括湿热互动与建筑围护结构》.pdf
  • ASHRAE NA-04-9-1-2004 Application of Conduction Transfer Functions and Periodic Response Factors in Cooling Load Calculation Procedures《传导传递函数和在冷负荷计算程序中的周期响应因子的应用》.pdf ASHRAE NA-04-9-1-2004 Application of Conduction Transfer Functions and Periodic Response Factors in Cooling Load Calculation Procedures《传导传递函数和在冷负荷计算程序中的周期响应因子的应用》.pdf
  • ASHRAE NA-04-9-2004 Symposium on Load Calculations《负荷计算的研讨会》.pdf ASHRAE NA-04-9-2004 Symposium on Load Calculations《负荷计算的研讨会》.pdf
  • ASHRAE NA-04-9-2A-2004 Heat Loss from Electrical and Control Equipment in Industrial Plants Part 1 - Methods and Scope (RP-1104)《在工业厂房中的电机及控制设备的热损失 第1部分-方法和范围RP-1104》.pdf ASHRAE NA-04-9-2A-2004 Heat Loss from Electrical and Control Equipment in Industrial Plants Part 1 - Methods and Scope (RP-1104)《在工业厂房中的电机及控制设备的热损失 第1部分-方法和范围RP-1104》.pdf
  • 相关搜索

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

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