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

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

1、国家二级 C语言机试(操作题)模拟试卷 282及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.下列给定程序中已建立一个带头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数 fun的功能是:把形参 x的值放入一个新结点并插入链表中,使插入后各结点数据域中的数据仍保持递增有序。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdioh #includestdlibh #define N 8 typedef

2、struct list int data; struer liSt*next; SLIST; void fun(SLIST *h,int x) SLISTp,*q,*s; s=(SLIST*)malloc(Sizeof (SLIST); *found* Sdata= 【1】 ; q=h; P=hnext; while(p!=NULLxpdata) *found* q= 【2】 ; p=pnext; snext=p; *found* qnext= 【3】 ; SLIST * creatlist(int*a) SLIST*h,*P,*q;int i ; h=P=(SLIST*)malloc(siz

3、eof(SLIST); for(i=0;iN;i+) q=(SLIST*)malloc(sizeof(SLIST); qdata=ai;PnexL=q;p=q; pnexL=0 ; return h; void outlist(SLIST*h) SLIST*P; P=hnext; if(P=NULL) printf(“nThe list is NULL!n“);else printf(“nHead“); doprintf(“d“,P data); P=Pnext; while(p!=NULL);printf(“Endn“); main() SLIST*head; int X; int aN=1

4、1,12,15,18,19,22,25,29); head=treatlist(a); printf(“nThe list before inserting:n“); outlist(head); printf(“nEnter a number: “); scanf(“d“,x); fun(head,x); printf(“nThe list after inserting:n“); outliSt(head); (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.给定程序 MODI1C 中,fun 函数的功能是:删除 b所指数组中小于 10的数据。主函数中输出删除后数组中余下

5、的数据。请改正函数 fun中指定部位的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includestdioh#includestdlibh#define N 20int fun(int *b)*found* int tN,i,num for(i=0;iN;i+) if(bi=10) *found* t+num=bi; *found* for(i=0;inun;i+) bi=ti; return(num);main() int aN,i,num; printf(“a 数组中的数据:n“); for(i=0;iN;i+) ai=ran

6、d()21; printf(“4 d“,ai);) printf(“n“); num=fun(a); for(i=0;inum;i+) printf(“4 d“,ai), printf(“n“);(分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.请编写函数 fun,其功能是:将 M行 N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。例如,若二维数组中的数据为 W W W WS S S SH H H H则字符串中的内容应是:WSHWSHWSHWSH。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语

7、句。试题程序:#includestdioh#define M 3#define N 4void fun(char(*s)N,char*b)void main() char a100,wMN=W,W,W,W,S,S,S,S,H,H,H,H; int i,j; printf(“The matrix:n“); for(i=0;iM;i+) for(j=0;jN;j+) printf(“3c“,wij); printf(“n“); fun(w,a); printf(“The A string:n“); puts(a); printf(“nn“);(分数:2.00)_国家二级 C语言机试(操作题)模拟试

8、卷 282答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.下列给定程序中已建立一个带头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数 fun的功能是:把形参 x的值放入一个新结点并插入链表中,使插入后各结点数据域中的数据仍保持递增有序。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdioh #includestdlibh #define N 8 typedef struct list int dat

9、a; struer liSt*next; SLIST; void fun(SLIST *h,int x) SLISTp,*q,*s; s=(SLIST*)malloc(Sizeof (SLIST); *found* Sdata= 【1】 ; q=h; P=hnext; while(p!=NULLxpdata) *found* q= 【2】 ; p=pnext; snext=p; *found* qnext= 【3】 ; SLIST * creatlist(int*a) SLIST*h,*P,*q;int i ; h=P=(SLIST*)malloc(sizeof(SLIST); for(i=0

10、iN;i+) q=(SLIST*)malloc(sizeof(SLIST); qdata=ai;PnexL=q;p=q; pnexL=0 ; return h; void outlist(SLIST*h) SLIST*P; P=hnext; if(P=NULL) printf(“nThe list is NULL!n“);else printf(“nHead“); doprintf(“d“,P data); P=Pnext; while(p!=NULL);printf(“Endn“); main() SLIST*head; int X; int aN=11,12,15,18,19,22,25

11、29); head=treatlist(a); printf(“nThe list before inserting:n“); outlist(head); printf(“nEnter a number: “); scanf(“d“,x); fun(head,x); printf(“nThe list after inserting:n“); outliSt(head); (分数:2.00)_正确答案:(正确答案:(1)x (2)p (3)s)解析:解析:填空 1:将形参 x赋值给结点的数据域。 填空 2和填空 3:将新的结点和原有链表中的结点进行比较。二、程序修改题(总题数:1,分数:2

12、00)2.给定程序 MODI1C 中,fun 函数的功能是:删除 b所指数组中小于 10的数据。主函数中输出删除后数组中余下的数据。请改正函数 fun中指定部位的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includestdioh#includestdlibh#define N 20int fun(int *b)*found* int tN,i,num for(i=0;iN;i+) if(bi=10) *found* t+num=bi; *found* for(i=0;inun;i+) bi=ti; return(num);m

13、ain() int aN,i,num; printf(“a 数组中的数据:n“); for(i=0;iN;i+) ai=rand()21; printf(“4 d“,ai);) printf(“n“); num=fun(a); for(i=0;inum;i+) printf(“4 d“,ai), printf(“n“);(分数:2.00)_正确答案:(正确答案:(1)int tN,i,num:0; (2)thum+=bi;或tnum=bj;hum+; (3)for(i=0;inum;i+)解析:解析:要删除数组 h中小于 10的数,应依次取出数组数组 b中的元素与 10进行比较,若不小于10,

14、则将其存入数组 t中,遍历完成后,数组 t中的元素即为所求,再将数组 t中的元素保存到数组 b中即可。 (1)元素 num存放不小于 10的元素的个数,应将其初始化为 0。 (2)将数组 h中不小于 10的元素存入数组 t中,同时使数组 t的下标加 1。 (3)语法错误,没有 nun这个变量,应该为 num。三、程序设计题(总题数:1,分数:2.00)3.请编写函数 fun,其功能是:将 M行 N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。例如,若二维数组中的数据为 W W W WS S S SH H H H则字符串中的内容应是:WSHWSHWSHWSH。注意:部分源程序给出如下

15、请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序:#includestdioh#define M 3#define N 4void fun(char(*s)N,char*b)void main() char a100,wMN=W,W,W,W,S,S,S,S,H,H,H,H; int i,j; printf(“The matrix:n“); for(i=0;iM;i+) for(j=0;jN;j+) printf(“3c“,wij); printf(“n“); fun(w,a); printf(“The A string:n“); puts(a); printf(“nn“);(分数:2.00)_正确答案:(正确答案:void fun(qhar(*s)N,char*b) int i,j,k=0; for(i=0;iN;i+) *按列的顺序依次放到一个字符串中 8 for(j=0;jM;j+) bk+=sji; bk=0; )解析:解析:看到程序后,很容易便能想到用循环嵌套的方法,本题中按列的顺序依次放到一个字符串中,所以列标变化慢,行标变化快。 注意:第 1个循环条件为 iN(即列);第 2个循环条件为 jM(即行),因为在循环的嵌套中越在内层,循环变化就越快。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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