【计算机类职业资格】二级C语言-313及答案解析.doc

上传人:花仙子 文档编号:1325192 上传时间:2019-10-17 格式:DOC 页数:7 大小:33.50KB
下载 相关 举报
【计算机类职业资格】二级C语言-313及答案解析.doc_第1页
第1页 / 共7页
【计算机类职业资格】二级C语言-313及答案解析.doc_第2页
第2页 / 共7页
【计算机类职业资格】二级C语言-313及答案解析.doc_第3页
第3页 / 共7页
【计算机类职业资格】二级C语言-313及答案解析.doc_第4页
第4页 / 共7页
【计算机类职业资格】二级C语言-313及答案解析.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

1、二级 C 语言-313 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 不得增行或删行,也不得更改程序的结构! 给定源程序: #includestdio.h #includestdlib.h #define N 5 typedef struct node int data; struct no

2、de *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;iN;i+) q=(NODE*)malloc(sizeof(NOD

3、E); 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 printf(“/nHead“); do printf(“-%d“,p-data);p=p-next; while(p!=NULL); printf(“-End/n“); main() NODE*head; int aN=2,4,6,8,10; head=cr

4、eatlist(a); printf(“/nThe original list:/n“); outlist(head); fun(head); printf(“/nThe list after inverting:/n“); outlist(head); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.给定程序中函数 fun 的功能是:计算 s 所指字符串中含有 t 所指字符串的数目,并作为函数值返回。 请改正函数 fun 中指定部位的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行也不得更改程序的结构! 给定源程序: #includestdi

5、o.h #includestring.h #define N 80 int fun(char*s,char*t) int n; char*p,*r; n=0; while(*s) p=s; /*found*/ r=p; while(*r) if(*r=*p)r+;p+; else break; /*found*/ if(*r=0) n+; s+; return n; main() char aN,bN;int m; printf(“/nPlease enter string a:“);gets(a); printf(“/nPlease enter substring b:“);gets(b);

6、 m=fun(a,b); printf(“/nThe result is:m=%d/n“,m); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写函数 fun,函数的功能是:将放在字符串数组中的 M 个字符串(每串的长度不超过 N),按顺序合并组成一个新的字符串。函数 fun 中给出的语句仅供参考。 例如,字符串数组中的 M 个字符串为 AAAA BBBBBBB CC 则合并后的字符串的内容应是:AAAABBBBBBBCC。 提示:strcat(a,b)的功能是将字符串 b 复制到字符串 a 的串尾上,成为一个新串。 请勿改动主函数 main 和其它函数中的任何内容

7、,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #inclndestdio.h #includestring.h #define M 3 #define N 20 void fun(char aMN,char *b) /*以下代码仅供参考*/ int i;*b=0; main() char wMN=“AAAA“,“BBBBBBB“,“CC“,a100; inti; printf(“The string:/n“); for(i=0;iM;i+)puts(wi); printf(“/n“); fun(w,a); printf(“The A string:/n“); printf

8、(“%s“,a);printf(“/n/n“); (分数:40.00)_二级 C 语言-313 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 不得增行或删行,也不得更改程序的结构! 给定源程序: #includestdio.h #includestdlib.h #define N 5 type

9、def struct node int data; struct node *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=

10、0;iN;i+) q=(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 printf(“/nHead“); do printf(“-%d“,p-data);p=p-next; while(p!=NULL); printf(“-End/n“); main() NO

11、DE*head; int aN=2,4,6,8,10; head=creatlist(a); printf(“/nThe original list:/n“); outlist(head); fun(head); printf(“/nThe list after inverting:/n“); outlist(head); (分数:30.00)解析:(1)next (2)0 (3)r 解析 填空 1:本空考查了为 p 赋初值,根据题目的要求是将带头结点的单向链表逆置可知,p 的初值应该为 h-next。 填空 2:if 判断语句表明当 p 等于什么时就要返回,因此只能当 p 等于 NULL 时

12、返回,不用做后面的链表的逆置了。 填空 3:把 q 的指针向后移动,才能实现将带头结点的单向链表逆置。因此本空填写 r。二、程序改错题(总题数:1,分数:30.00)2.给定程序中函数 fun 的功能是:计算 s 所指字符串中含有 t 所指字符串的数目,并作为函数值返回。 请改正函数 fun 中指定部位的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行也不得更改程序的结构! 给定源程序: #includestdio.h #includestring.h #define N 80 int fun(char*s,char*t) int n; char*p,*r; n=0

13、; while(*s) p=s; /*found*/ r=p; while(*r) if(*r=*p)r+;p+; else break; /*found*/ if(*r=0) n+; s+; return n; main() char aN,bN;int m; printf(“/nPlease enter string a:“);gets(a); printf(“/nPlease enter substring b:“);gets(b); m=fun(a,b); printf(“/nThe result is:m=%d/n“,m); (分数:30.00)解析:(1)r=t; (2)if(*r

14、=0) 解析 从字符串 s 中找出子字符串的方法是:从第一个字符开始,对字符串进行遍历,若s 串的当前字符等于 t 串的第一个字符,两字符串的指针自动加 1,继续比较下一个字符;若比较至字符串 t 的末尾,则跳出循环;若 s 串的字符与 t 串的字符不对应相同,则继续对 s 串的下一个字符进行处理。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 fun,函数的功能是:将放在字符串数组中的 M 个字符串(每串的长度不超过 N),按顺序合并组成一个新的字符串。函数 fun 中给出的语句仅供参考。 例如,字符串数组中的 M 个字符串为 AAAA BBBBBBB CC 则合并后的字符串的

15、内容应是:AAAABBBBBBBCC。 提示:strcat(a,b)的功能是将字符串 b 复制到字符串 a 的串尾上,成为一个新串。 请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #inclndestdio.h #includestring.h #define M 3 #define N 20 void fun(char aMN,char *b) /*以下代码仅供参考*/ int i;*b=0; main() char wMN=“AAAA“,“BBBBBBB“,“CC“,a100; inti; printf(“The string:/n“); for(i=0;iM;i+)puts(wi); printf(“/n“); fun(w,a); printf(“The A string:/n“); printf(“%s“,a);printf(“/n/n“); (分数:40.00)_正确答案:()解析:for(i=0;iM;i+) strcat(b,ai); 解析 本题考查:字符串连接操作,使用 strcat 函数将 ai的内容里阿尼额到 b 的末尾。

展开阅读全文
相关资源
猜你喜欢
  • DIN 6800-2 Berichtigung 1-2010 de 8543 Procedures of dosimetry with probe type detectors for photon and electron radiation - Part 2 Ionization chamber dosimetry of high energy phot.pdf DIN 6800-2 Berichtigung 1-2010 de 8543 Procedures of dosimetry with probe type detectors for photon and electron radiation - Part 2 Ionization chamber dosimetry of high energy phot.pdf
  • DIN 6800-2-2008 Procedures of dosimetry with probe type detectors for photon and electron radiation - Part 2 Ionization chamber dosimetry of high energy photon and electron radiati.pdf DIN 6800-2-2008 Procedures of dosimetry with probe type detectors for photon and electron radiation - Part 2 Ionization chamber dosimetry of high energy photon and electron radiati.pdf
  • DIN 6800-4-2000 Procedures of dosimetry with probe-type detectors for photon and electron radiation - Part 4 Film dosimetry《光子辐射和电子辐射用探针型探测器的剂量测定程序 第4部分 胶片剂量测定法》.pdf DIN 6800-4-2000 Procedures of dosimetry with probe-type detectors for photon and electron radiation - Part 4 Film dosimetry《光子辐射和电子辐射用探针型探测器的剂量测定程序 第4部分 胶片剂量测定法》.pdf
  • DIN 6800-5-2005 Procedures of dosimetry with probe-type detectors for photon and electron radiation - Part 5 Thermoluminescence dosimetry《光子辐射和电子辐射用带探针型探测器的剂量测定程序 第5部分 热致发光剂量测定》.pdf DIN 6800-5-2005 Procedures of dosimetry with probe-type detectors for photon and electron radiation - Part 5 Thermoluminescence dosimetry《光子辐射和电子辐射用带探针型探测器的剂量测定程序 第5部分 热致发光剂量测定》.pdf
  • DIN 6802-1-1991 Neutron dosimetry special terms and definitions《中子剂量学 专业术语和定义》.pdf DIN 6802-1-1991 Neutron dosimetry special terms and definitions《中子剂量学 专业术语和定义》.pdf
  • DIN 6802-2-1999 Neutron dosimetry - Part 2 Conversion coefficients for the calculation of ambient and personal dose equivalent from the neutron fluence and correction factors for r.pdf DIN 6802-2-1999 Neutron dosimetry - Part 2 Conversion coefficients for the calculation of ambient and personal dose equivalent from the neutron fluence and correction factors for r.pdf
  • DIN 6802-3-2007 Neutron dosimetry - Part 3 Methods for neutron measurement in radiation protection《中子剂量学 第3部分 辐射防护中中子测量方法》.pdf DIN 6802-3-2007 Neutron dosimetry - Part 3 Methods for neutron measurement in radiation protection《中子剂量学 第3部分 辐射防护中中子测量方法》.pdf
  • DIN 6802-4-1998 Neutron dosimetry - Part 4 Measurement technique for individual dosimetry using albedo dosimeters《中子剂量学 第4部分 用反射率剂量仪进行单个剂量测量的技术》.pdf DIN 6802-4-1998 Neutron dosimetry - Part 4 Measurement technique for individual dosimetry using albedo dosimeters《中子剂量学 第4部分 用反射率剂量仪进行单个剂量测量的技术》.pdf
  • DIN 6802-6-2013 Neutron dosimetry Part 6 Methods for determination of absorbed dose using ionisation chambers《中子剂量学 第6部分 采用电离室对吸收剂量的测定方法》.pdf DIN 6802-6-2013 Neutron dosimetry Part 6 Methods for determination of absorbed dose using ionisation chambers《中子剂量学 第6部分 采用电离室对吸收剂量的测定方法》.pdf
  • 相关搜索

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

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