【计算机类职业资格】全国计算机二级C语言上机试题36+2015年及答案解析.doc

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

1、全国计算机二级 C 语言上机试题 36+2015 年及答案解析(总分:30.00,做题时间:90 分钟)1.给定程序中,函数 fun 的功能是:统计出带有头结点的单向链表中结点的个数,存放在形参 n 所指的存储单元中。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include #define N 8 typedef struct list int data; struct list *next; SLIST; SLIST *creatl

2、ist(int *a); void outlist(SLIST *); void fun( SLIST *h, int *n) SLIST *p; /*found*/ _1_=0; p=h-next; while(p) (*n)+; /*found*/ p=p-_2_; main() SLIST *head; int aN=12,87,45,32,91,16,20,48, num; head=creatlist(a); outlist(head); /*found*/ fun(_3_, printf(“/nnumber=%d/n“,num); SLIST *creatlist(int a) S

3、LIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST); for(i=0; i q=(SLIST *)malloc(sizeof(SLIST); q-data=ai; p-next=q; p=q; p-next=0; return h; void outlist(SLIST *h) SLIST *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!

4、NULL); printf(“-End/n“); (分数:10.00)_2.给定程序 MODI1.C 中函数 fun 的功能是:求出 s 所指字符串中最后一次出现的 t 所指子字符串的地址,通过函数值返回,在主函数中输出从此地址开始的字符串;若未找到,则函数值为 NULL。 例如,当字符串中的内容为:“abcdabfabcdx“,t 中的内容为:“ab“时, 输出结果应是:abcdx。 当字符串中的内容为:“abcdabfabcdx“,t 中的内容为:“abd“时,则程序输出未找到信息:not be found!。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,

5、不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include char * fun (char *s, char *t ) char *p , *r, *a; /*found*/ a = Null; while ( *s ) p = s; r = t; while ( *r ) /*found*/ if ( r = p ) r+; p+; else break; if ( *r = /0 ) a = s; s+; return a ; main() char s100, t100, *p; printf(“/nPlease enter string S :“); s

6、canf(“%s“, s ); printf(“/nPlease enter substring t :“); scanf(“%s“, t ); p = fun( s, t ); if ( p ) printf(“/nThe result is : %s/n“, p); else printf(“/nNot found !/n“ ); (分数:10.00)_3.函数 fun 的功能是: 将 s 所指字符串中除了下标为偶数、同时 ASCII 值也为偶数的字符外,其余的全都删除;串中剩余字符所形成的一个新串放在 t 所指的数组中。 例如,若 s 所指字符串中的内容为:“ABCDEFG123456“

7、其中字符 A 的 ASCII 码值为奇数,因此应当删除;其中字符 B 的 ASCII 码值为偶数,但在数组中的下标为奇数,因此也应当删除;而字符 2 的 ASCII 码值为偶数,所在数组中的下标也为偶数,因此不应当删除,其它依此类推。最后 t 所指的数组中的内容应是:“246“。 注意: 部分源程序存在文件PROG1.C 中。请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #include #include void fun(char *s, char t) main() char s100, t100; printf(“/

8、nPlease enter string S:“); scanf(“%s“, s); fun(s, t); printf(“/nThe result is: %s/n“, t); NONO(); (分数:10.00)_全国计算机二级 C 语言上机试题 36+2015 年答案解析(总分:30.00,做题时间:90 分钟)1.给定程序中,函数 fun 的功能是:统计出带有头结点的单向链表中结点的个数,存放在形参 n 所指的存储单元中。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。不得增行或删行,也不得更改程序的结构

9、 给定源程序: #include #include #define N 8 typedef struct list int data; struct list *next; SLIST; SLIST *creatlist(int *a); void outlist(SLIST *); void fun( SLIST *h, int *n) SLIST *p; /*found*/ _1_=0; p=h-next; while(p) (*n)+; /*found*/ p=p-_2_; main() SLIST *head; int aN=12,87,45,32,91,16,20,48, num;

10、 head=creatlist(a); outlist(head); /*found*/ fun(_3_, printf(“/nnumber=%d/n“,num); SLIST *creatlist(int a) SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST); for(i=0; i q=(SLIST *)malloc(sizeof(SLIST); q-data=ai; p-next=q; p=q; p-next=0; return h; void outlist(SLIST *h) SLIST *p; p=h-next; if

11、 (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“); (分数:10.00)_正确答案:(第一处:对 n 所指的存储单元进行初始化,所以应填:*n。 第二处:指向 p 的下一个结点,所以应填:next。 第三处:函数调用,在主函数中已经给出了 head,所以应填:head。)解析:2.给定程序 MODI1.C 中函数 fun 的功能是:求出 s 所指字符串中最后一次出现的 t 所指子字

12、符串的地址,通过函数值返回,在主函数中输出从此地址开始的字符串;若未找到,则函数值为 NULL。 例如,当字符串中的内容为:“abcdabfabcdx“,t 中的内容为:“ab“时, 输出结果应是:abcdx。 当字符串中的内容为:“abcdabfabcdx“,t 中的内容为:“abd“时,则程序输出未找到信息:not be found!。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include char * fun (char *s, char *t ) char *p , *r,

13、a; /*found*/ a = Null; while ( *s ) p = s; r = t; while ( *r ) /*found*/ if ( r = p ) r+; p+; else break; if ( *r = /0 ) a = s; s+; return a ; main() char s100, t100, *p; printf(“/nPlease enter string S :“); scanf(“%s“, s ); printf(“/nPlease enter substring t :“); scanf(“%s“, t ); p = fun( s, t );

14、if ( p ) printf(“/nThe result is : %s/n“, p); else printf(“/nNot found !/n“ ); (分数:10.00)_正确答案:(第一处:指向空指针错误,Null 应 NULL。 第二处:比较指针位置的值是否相等,所以应改为:if(*r=*p)。)解析:3.函数 fun 的功能是: 将 s 所指字符串中除了下标为偶数、同时 ASCII 值也为偶数的字符外,其余的全都删除;串中剩余字符所形成的一个新串放在 t 所指的数组中。 例如,若 s 所指字符串中的内容为:“ABCDEFG123456“,其中字符 A 的 ASCII 码值为奇数,

15、因此应当删除;其中字符 B 的 ASCII 码值为偶数,但在数组中的下标为奇数,因此也应当删除;而字符 2 的 ASCII 码值为偶数,所在数组中的下标也为偶数,因此不应当删除,其它依此类推。最后 t 所指的数组中的内容应是:“246“。 注意: 部分源程序存在文件PROG1.C 中。请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #include #include void fun(char *s, char t) main() char s100, t100; printf(“/nPlease enter string S:“); scanf(“%s“, s); fun(s, t); printf(“/nThe result is: %s/n“, t); NONO(); (分数:10.00)_正确答案:(void fun(char *s, char t) int i, j = 0 ; for(i = 0 ; i strlen(s) ; i += 2) if(si % 2 = 0) tj+ = si ; tj = 0 ; )解析:

展开阅读全文
相关资源
猜你喜欢
  • BS EN ISO 14051-2011 Environmental management Material flow cost accounting General framework《环境管理 物料流成本核算 通用框架》.pdf BS EN ISO 14051-2011 Environmental management Material flow cost accounting General framework《环境管理 物料流成本核算 通用框架》.pdf
  • BS EN ISO 14063-2010 Environmental management Environmental communication Guidelines and examples《环境管理 环境沟通 准则和实例》.pdf BS EN ISO 14063-2010 Environmental management Environmental communication Guidelines and examples《环境管理 环境沟通 准则和实例》.pdf
  • BS EN ISO 14064-1-2012 Greenhouse gases Specification with guidance at the organization level for quantification and reporting of greenhouse gas emissions and removals《温室气体 温室气体辐射和.pdf BS EN ISO 14064-1-2012 Greenhouse gases Specification with guidance at the organization level for quantification and reporting of greenhouse gas emissions and removals《温室气体 温室气体辐射和.pdf
  • BS EN ISO 14064-2-2012 Greenhouse gases Specification with guidance at the project level for quantification monitoring and reporting of greenhouse gas emission reductions or remova.pdf BS EN ISO 14064-2-2012 Greenhouse gases Specification with guidance at the project level for quantification monitoring and reporting of greenhouse gas emission reductions or remova.pdf
  • BS EN ISO 14064-3-2012 Greenhouse gases Specification with guidance for the validation and verification of greenhouse gas assertions《温室气体 温室气体认定用验证和确认的规范与指南》.pdf BS EN ISO 14064-3-2012 Greenhouse gases Specification with guidance for the validation and verification of greenhouse gas assertions《温室气体 温室气体认定用验证和确认的规范与指南》.pdf
  • BS EN ISO 14065-2013 Greenhouse gases Requirements for greenhouse gas validation and verification bodies for use in accreditation or other forms of recognition《温室气体 认证或其他承认形式中使用温室气.pdf BS EN ISO 14065-2013 Greenhouse gases Requirements for greenhouse gas validation and verification bodies for use in accreditation or other forms of recognition《温室气体 认证或其他承认形式中使用温室气.pdf
  • BS EN ISO 14087-2011 Leather Physical and mechanical tests Determination of bending force《皮革 物理和机械试验 弯曲力测定》.pdf BS EN ISO 14087-2011 Leather Physical and mechanical tests Determination of bending force《皮革 物理和机械试验 弯曲力测定》.pdf
  • BS EN ISO 14088-2012 Leather Chemical tests Quantitative analysis of tanning agents by filter method《皮革 化学试验 通过过滤法进行制革剂的量化分析》.pdf BS EN ISO 14088-2012 Leather Chemical tests Quantitative analysis of tanning agents by filter method《皮革 化学试验 通过过滤法进行制革剂的量化分析》.pdf
  • BS EN ISO 14113-2013 Gas welding equipment Rubber and plastics hose and hose assemblies for use with industrial gases up to 450 bar (45 MPa)《气焊设备 450 bar(45 MPa)以下工业气体用橡胶和塑料软管及软管总成.pdf BS EN ISO 14113-2013 Gas welding equipment Rubber and plastics hose and hose assemblies for use with industrial gases up to 450 bar (45 MPa)《气焊设备 450 bar(45 MPa)以下工业气体用橡胶和塑料软管及软管总成.pdf
  • 相关搜索

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

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