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

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

1、国家二级 C语言机试(操作题)模拟试卷 357及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中已建立一个带有头结点的单向链表,在 main函数中将多次调用 fun函数,每调用一次 fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1C 中。 不得增行或删行,也不得更改程序的结构!1 #includestdioh2 #includestdlibh3 #define N 84 typedef struct l

2、ist5 int data;6 struct list *next;7 SLIST;8 void fun(SLIST *p)9 SLIST *t,*s;10 t=p-next;s=p;11 while(t-next!=NULL)12 s=t;13 *found*14 t=t-_1_;15 16 *found*17 printf(d,_2_ );18 s-next=NULL;19 *found*20 free( _3_ );21 22 SLIST *creatlist(int *a)23 SLIST *h,*p,*q;int i;24 h=p(SLIST*)malloc(sizeof(SLIST

3、);25 for(i=0;iN;i+)26 q=(SLIST *)malloc(sizeof(SLIST);27 q-data=ai;p-next=q;p=q;28 29 p-next=0;30 return h;31 32 void outlist(SLIST *h)33 SLIST *p;34 p=h-next;35 if (p=NULL)printf(nThe list is NULL!n);36 else37 printf(nHead);38 do printf(-d,p-data);p=p-next; while(p!=NULL);39 printf(-Endn);40 41 42

4、main()43 SLIST *head;44 int aN=11,12,15,18,19,22,25,29;45 head=creatlist(a);46 printf(nOutput from head:n);outlist(head);47 printf(nOutput from tail:n);48 while(head-next!=NULL)49 fun(head);50 printf(nn);51 printf(nOutput from head again:n);outlist(head);52 53 (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.给定程序

5、MODI1C 中函数 fun的功能是:将 p所指字符串中的所有字符复制到 b中,要求每复制三个字符之后插入一个空格。 例如,在调用 fun函数之前给 a输入字符串:ABCDEFGHIJK,调用函数之后,字符数组 b中的内容则为:ABC DEF GHI JK。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。1 #includestdioh2 void fun(char *p,char *b)3 int i,k=0;4 while(*p)5 i=1;6 while(i=39 k+; p+; i+;10 11 if(*p)12 13 *

6、found*14 bk+= ;15 16 17 bk=0;18 19 main()20 char a80,b80;21 printf(Enter a string:);gets(a);22 printf(The original string:);puts(a);23 fun(a,b);24 printf(nThe string after insert space:);puts(b);printf(nn);25 (分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.请编写函数 fun,它的功能是:计算并输出 n(包括 n)以内能被 5或 9整除的所有自然数的倒数之和。 例如,在

7、主函数中从键盘给 n输入 20后,输出为:s=0583333。 注意:要求 n的值不大于 100。 部分源程序在文件 PROG1C 中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。1 #includestdioh2 double fun(int n)3 45 6 NONO()7 *请在此函数内打开文件,输入测试数据,调用 fun函数,输出数据,关闭文件。*8 FILE *rf *wf;int n,i;double s;9 rf=fopen(indat,r);10 wf=fopen(outdat,w);11 for(i=0;i10 ; i+)

8、 12 fscanf(rf,d,n);13 s=fun(n);14 fprintf(wf,ifn,s);15 16 fclose(rf);fclose(wf);17 18 main()19 int n;double s;20 printf(nInput n:);scanf(d,n);21 s=fun(n);22 printf(nns=fn,s);23 NONO();(分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 357答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中已建立一个带有头结点的单向链表,在 main函数中将多次调用

9、 fun函数,每调用一次 fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1C 中。 不得增行或删行,也不得更改程序的结构!1 #includestdioh2 #includestdlibh3 #define N 84 typedef struct list5 int data;6 struct list *next;7 SLIST;8 void fun(SLIST *p)9 SLIST *t,*s;10 t=p-next;s=p;11 while(t-next

10、NULL)12 s=t;13 *found*14 t=t-_1_;15 16 *found*17 printf(d,_2_ );18 s-next=NULL;19 *found*20 free( _3_ );21 22 SLIST *creatlist(int *a)23 SLIST *h,*p,*q;int i;24 h=p(SLIST*)malloc(sizeof(SLIST);25 for(i=0;iN;i+)26 q=(SLIST *)malloc(sizeof(SLIST);27 q-data=ai;p-next=q;p=q;28 29 p-next=0;30 return h;

11、31 32 void outlist(SLIST *h)33 SLIST *p;34 p=h-next;35 if (p=NULL)printf(nThe list is NULL!n);36 else37 printf(nHead);38 do printf(-d,p-data);p=p-next; while(p!=NULL);39 printf(-Endn);40 41 42 main()43 SLIST *head;44 int aN=11,12,15,18,19,22,25,29;45 head=creatlist(a);46 printf(nOutput from head:n);

12、outlist(head);47 printf(nOutput from tail:n);48 while(head-next!=NULL)49 fun(head);50 printf(nn);51 printf(nOutput from head again:n);outlist(head);52 53 (分数:2.00)_正确答案:(正确答案:(1)next (2)t-data (3)t)解析:解析:第一空:fun 函数中的循环目的是找到尾结点“while(t-next!=NULL)”,利用结点变量s和 t,s 指向当前节点,t 不断指向下一个结点,因此第一空处应该是“t=t-next;”

13、第二空:这里是输出尾结点中的数据,已经利用循环找到了尾结点 t,t 的数据是 t-data,因此第二空处应该为“printf(d,t-data);”。第三空:输出尾结点数据之后删除尾结点,使用 free,又因为尾结点是 t,因此第三空处应该为“free(t);”。二、程序修改题(总题数:1,分数:2.00)2.给定程序 MODI1C 中函数 fun的功能是:将 p所指字符串中的所有字符复制到 b中,要求每复制三个字符之后插入一个空格。 例如,在调用 fun函数之前给 a输入字符串:ABCDEFGHIJK,调用函数之后,字符数组 b中的内容则为:ABC DEF GHI JK。 请改正程序中的错

14、误,使它能得出正确结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。1 #includestdioh2 void fun(char *p,char *b)3 int i,k=0;4 while(*p)5 i=1;6 while(i=39 k+; p+; i+;10 11 if(*p)12 13 *found*14 bk+= ;15 16 17 bk=0;18 19 main()20 char a80,b80;21 printf(Enter a string:);gets(a);22 printf(The original string:);puts(a);23 fun

15、a,b);24 printf(nThe string after insert space:);puts(b);printf(nn);25 (分数:2.00)_正确答案:(正确答案:(1)bk=*p; (2)bk+= ;)解析:解析:函数的功能是将字符串 p中的所有字符复制到字符串 b中。 (1)p 是指针,p 存放的内容是地址值,第一标识下“bk=p;”含义是将 p存放的地址内容赋给 bk,而不是把 p指向的地址拷贝到bk,显然不符合题意,应改成“bk=*p;”,*p 是取 p指向的地址的内容。 (2)第二个标识符下是复制三个字符后在 b中插入空格,原题中给出的“bk+1= ;,在 C语言

16、中字符常量是由单引号括起的单个字符,即空格字符应为 ,而“ ”是表示字符串常量且该字符串中只有一个空格字符。第二标识下是将空格字符复制给 bk+,因此第二标识下应改为“bk+=;”。三、程序设计题(总题数:1,分数:2.00)3.请编写函数 fun,它的功能是:计算并输出 n(包括 n)以内能被 5或 9整除的所有自然数的倒数之和。 例如,在主函数中从键盘给 n输入 20后,输出为:s=0583333。 注意:要求 n的值不大于 100。 部分源程序在文件 PROG1C 中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。1 #includes

17、tdioh2 double fun(int n)3 45 6 NONO()7 *请在此函数内打开文件,输入测试数据,调用 fun函数,输出数据,关闭文件。*8 FILE *rf *wf;int n,i;double s;9 rf=fopen(indat,r);10 wf=fopen(outdat,w);11 for(i=0;i10 ; i+) 12 fscanf(rf,d,n);13 s=fun(n);14 fprintf(wf,ifn,s);15 16 fclose(rf);fclose(wf);17 18 main()19 int n;double s;20 printf(nInput n

18、);scanf(d,n);21 s=fun(n);22 printf(nns=fn,s);23 NONO();(分数:2.00)_正确答案:(正确答案:1 int i; 2 double sum=00; 3 for(i=1; i=n; i+) 4 if(i5=0 i9=0)*被 5或 9整除* 5 sum+=10i; 6 return sum;)解析:解析:程序功能是计算并输出 n(包括力)以内能被 5或 9整除的所有自然数的倒数之和。 (1)首先,通过循环,判断小于等于 n的每一个整数是否符合题干中的要求。其中的判断条件能否被 5或者被 9整除为:i5=0i9=0。 (2)然后求得符合(1)要求的数的倒数的累加和。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO 14520-11-2006 Gaseous fire-extinguishing systems - Physical properties and system design - HFC 236fa extinguishant《气体灭火系统 物理性能和系统设计 HFC 236fa灭火剂》.pdf BS ISO 14520-11-2006 Gaseous fire-extinguishing systems - Physical properties and system design - HFC 236fa extinguishant《气体灭火系统 物理性能和系统设计 HFC 236fa灭火剂》.pdf
  • BS ISO 14520-2-2006 Gaseous fire-extinguishing systems - Physical properties and system design - CF3I extinguishant《气体灭火系统 物理性能和系统设计 CF3I灭火剂》.pdf BS ISO 14520-2-2006 Gaseous fire-extinguishing systems - Physical properties and system design - CF3I extinguishant《气体灭火系统 物理性能和系统设计 CF3I灭火剂》.pdf
  • BS ISO 14524-2009 Photography - Electronic still-picture Cameras - Methods for measuring optoelectronic conversion functions (OECFs)《摄影 数码照相机 光电转换函数(OECFs)的测量方法》.pdf BS ISO 14524-2009 Photography - Electronic still-picture Cameras - Methods for measuring optoelectronic conversion functions (OECFs)《摄影 数码照相机 光电转换函数(OECFs)的测量方法》.pdf
  • BS ISO 14531-2-2006 Plastics pipes and fittings - Crosslinked polyethylene (PE-X) pipe systems for the conveyance of gaseous fuels - Metric series - Specifications - Fittings for h.pdf BS ISO 14531-2-2006 Plastics pipes and fittings - Crosslinked polyethylene (PE-X) pipe systems for the conveyance of gaseous fuels - Metric series - Specifications - Fittings for h.pdf
  • BS ISO 14531-4-2006 Plastics pipes and fittings - Crosslinked polyethylene (PE-X) pipe systems for the conveyance of gaseous fuels - Metric series - Specifications - System design .pdf BS ISO 14531-4-2006 Plastics pipes and fittings - Crosslinked polyethylene (PE-X) pipe systems for the conveyance of gaseous fuels - Metric series - Specifications - System design .pdf
  • BS ISO 14535-2001 Photography - Room-light loading packages for electronic scanners and image-setting film and paper rolls - Dimensions and related requirements《摄影技术 电子扫描仪、成像胶片和胶卷的.pdf BS ISO 14535-2001 Photography - Room-light loading packages for electronic scanners and image-setting film and paper rolls - Dimensions and related requirements《摄影技术 电子扫描仪、成像胶片和胶卷的.pdf
  • BS ISO 14540-2013 Hydraulic fluid power Dimensions and requirements for screw-to-connect quick-action couplings for use at a pressure of 72 MPa (720 bar)《液压机液体 72 MPa(720 bar)下使用的螺.pdf BS ISO 14540-2013 Hydraulic fluid power Dimensions and requirements for screw-to-connect quick-action couplings for use at a pressure of 72 MPa (720 bar)《液压机液体 72 MPa(720 bar)下使用的螺.pdf
  • BS ISO 14541-2013 Hydraulic fluid power Dimensions and requirements for screw-to-connect quick-action couplings for general purpose《液压机液体 通用螺旋连接到连接器速动联轴器的尺寸规格和要求》.pdf BS ISO 14541-2013 Hydraulic fluid power Dimensions and requirements for screw-to-connect quick-action couplings for general purpose《液压机液体 通用螺旋连接到连接器速动联轴器的尺寸规格和要求》.pdf
  • BS ISO 14558-2016 Rubber Determination of residual unsaturation of hydrogenated nitrile butadiene rubber (HNBR) by infrared spectroscopy《橡胶 采用红外光谱法对氢化丁腈橡胶(HNBR)残余不饱和度的测定》.pdf BS ISO 14558-2016 Rubber Determination of residual unsaturation of hydrogenated nitrile butadiene rubber (HNBR) by infrared spectroscopy《橡胶 采用红外光谱法对氢化丁腈橡胶(HNBR)残余不饱和度的测定》.pdf
  • 相关搜索

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

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