【计算机类职业资格】全国计算机二级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 ; )解析:

展开阅读全文
相关资源
猜你喜欢
  • DIN 66223-4-1978 Fonts for optical character recognition format for page reader《光学字符识别用字体 页式阅读器用字符格式》.pdf DIN 66223-4-1978 Fonts for optical character recognition format for page reader《光学字符识别用字体 页式阅读器用字符格式》.pdf
  • DIN 66223-5-1985 Fonts for optical character recognition format for handheld scanner《光学字符识别用字体 第5部分 手动扫描仪用格式》.pdf DIN 66223-5-1985 Fonts for optical character recognition format for handheld scanner《光学字符识别用字体 第5部分 手动扫描仪用格式》.pdf
  • DIN 66224-2-1982 Instrumentation magnetic tape PCM recording with 10- or 12-bit data word application of auxiliary binary characters for time code《检测仪表用磁带 10位或12位数据字的脉码调制法的录制 第2部分 .pdf DIN 66224-2-1982 Instrumentation magnetic tape PCM recording with 10- or 12-bit data word application of auxiliary binary characters for time code《检测仪表用磁带 10位或12位数据字的脉码调制法的录制 第2部分 .pdf
  • DIN 66225-1979 Font H for optical character recognition characters writing rules and dimensions《光学字符识别H字体 字符、书写规则和尺寸》.pdf DIN 66225-1979 Font H for optical character recognition characters writing rules and dimensions《光学字符识别H字体 字符、书写规则和尺寸》.pdf
  • DIN 66226-1987 Information processing coding of machine readable characters MICR and OCR《信息处理 MICR 和 OCR可机读字符的编码》.pdf DIN 66226-1987 Information processing coding of machine readable characters MICR and OCR《信息处理 MICR 和 OCR可机读字符的编码》.pdf
  • DIN 66228-1-1978 Small punched cards for information processing dimensions requirements test《信息处理用小型穿孔卡片 第1部分 尺寸、要求和检验》.pdf DIN 66228-1-1978 Small punched cards for information processing dimensions requirements test《信息处理用小型穿孔卡片 第1部分 尺寸、要求和检验》.pdf
  • DIN 66229-1997 Information processing - Magnetic tape cassette and cartridge labelling and file structure for information interchange《信息处理 数据交换磁带盒标志和文件结构》.pdf DIN 66229-1997 Information processing - Magnetic tape cassette and cartridge labelling and file structure for information interchange《信息处理 数据交换磁带盒标志和文件结构》.pdf
  • DIN 6623-1-2017 Vertical steel tanks with less than 1 000 litre capacity for the above ground storage of liquids - Part 1 Singlewall《容量小于1000升的地上液体存储用立式储罐 第1部分 单壁》.pdf DIN 6623-1-2017 Vertical steel tanks with less than 1 000 litre capacity for the above ground storage of liquids - Part 1 Singlewall《容量小于1000升的地上液体存储用立式储罐 第1部分 单壁》.pdf
  • DIN 6623-2-2017 Vertical steel tanks with less than 1 000 litre capacity for the above ground storage of liquids - Part 2 Doublewall《容量小于1000升的地上液体存储用立式储罐 第2部分 双壁》.pdf DIN 6623-2-2017 Vertical steel tanks with less than 1 000 litre capacity for the above ground storage of liquids - Part 2 Doublewall《容量小于1000升的地上液体存储用立式储罐 第2部分 双壁》.pdf
  • 相关搜索

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

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