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

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

1、二级 C 语言-47 及答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充 main 函数,该函数的功能是:把字符串 str 中的字符向前移动一位,原来的第一个字符移动到字符串尾,结果仍然保存在原字符串中。 例如,输入“how do you do?”,则结果输出“ow do you do?h”。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。 试题程序: #include stdio. h #define N 80 main() char str

2、N, ch; int i; clrscr (); printf(“/n Input a string:In“); gets (str); printf(“/n* original string *In“); puts (str); ch=str 0; for (i=0; U U /U /U; i+) str i=str i+1; U U /U /U; printf(“/n * new string */n“); puts (str); (分数:30.00)填空项 1:_二、B改错题/B(总题数:1,分数:30.00)2.给定程序 MODI1.C 中函数 Creatlink 的功能是创建带头结点

3、的单向链表,并为各结点数据域赋 0(m-1)的值。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 文件 MODI1.C 内容如下: #includestdio.h #includestdlib.h typedef struet aa int data; struct aa *next; NODE; NODE *Creatlink(int m) NODE *h=NULL,*p,*s; int i; /*found*/ P=(NODE)malloc(sizeof(NODE); h=p; p-next=NULL; for(i=0;

4、im;i+) s=(NODE *)malloc(sizeof(NODE); s-data=i: s-next=p-next; p-next=s; p=p-next; /*found*/ return p; void outlink(NODE *h) NODE *p; p=h-next; printf(“/n/nTHE LIST: /n/n HEAD“); while(p) printf(“-%d“,p-data); p=p-next; printf(“/n“); void main() NODE *head; head=Creatlink(8); outlink(head); (分数:30.0

5、0)填空项 1:_三、B编程题/B(总题数:1,分数:40.00)3.请编写函数 fun,其功能是:将所有大于 1 小于整数 m 的非素数存入 xx 所指数组中,非素数的个数通过 k 传回。 例如:若输入 17,则应输出 9 和 4,6,8,9,10,12,14,15,16。 注意:部分源程序在文件 PROG1.C 中,请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 文件 PROG1.C 内容如下: #includestdio.h void fun(int m,int *k,int xx) void mainU /U int m,n,zz1

6、00; printf(“/nPlease enter an integer number between 10 and 100:“); scanf(“%d“, int i; clrscr (); printf(“/n Input a string:In“); gets (str); printf(“/n* original string *In“); puts (str); ch=str 0; for (i=0; U U /U /U; i+) str i=str i+1; U U /U /U; printf(“/n * new string */n“); puts (str); (分数:30.

7、00)填空项 1:_ (正确答案:1 stri+1 2stri=ch)解析:解析 填空 1:for 循环的条件是要移动的字符不为0,即还没有到字符串的最后一个字符。填空 2:ch 中保存了字符串的第一个字符,按题目要求移动到字符串尾,而 stri是/0的前一个字符,也就是字符串尾,故将 ch 赋给 stri。二、B改错题/B(总题数:1,分数:30.00)2.给定程序 MODI1.C 中函数 Creatlink 的功能是创建带头结点的单向链表,并为各结点数据域赋 0(m-1)的值。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构

8、 文件 MODI1.C 内容如下: #includestdio.h #includestdlib.h typedef struet aa int data; struct aa *next; NODE; NODE *Creatlink(int m) NODE *h=NULL,*p,*s; int i; /*found*/ P=(NODE)malloc(sizeof(NODE); h=p; p-next=NULL; for(i=0;im;i+) s=(NODE *)malloc(sizeof(NODE); s-data=i: s-next=p-next; p-next=s; p=p-next;

9、 /*found*/ return p; void outlink(NODE *h) NODE *p; p=h-next; printf(“/n/nTHE LIST: /n/n HEAD“); while(p) printf(“-%d“,p-data); p=p-next; printf(“/n“); void main() NODE *head; head=Creatlink(8); outlink(head); (分数:30.00)填空项 1:_ (正确答案:第 1 处:将“p=(NODE)malloc(sizeof(NODE);”改为“p=(NODE *)malloc(sizeof(NO

10、DE);”。 第 2 处:将“return p;”改为“return h;”。)解析:解析 函数 Creatlink 使用的算法是:循环 m 次,每次为一个新的结点在内存中划分相应的内存空间,将首地址赋给指针 p,并将这个新结点接入链表的末尾。对于第 1 处错误,指针 p 是一个指向结构体的指针,所以对 malloc 函数的返回值进行强制类型转换时,必须用“(NODE*)”。对于第 2 处错误,任何一个链表都必须知道第一个结点地址,创建链表的函数应该将头结点的地址作为函数值返回。程序中头结点的地址存放在 h 中,而不在指针 p 中。三、B编程题/B(总题数:1,分数:40.00)3.请编写函数

11、 fun,其功能是:将所有大于 1 小于整数 m 的非素数存入 xx 所指数组中,非素数的个数通过 k 传回。 例如:若输入 17,则应输出 9 和 4,6,8,9,10,12,14,15,16。 注意:部分源程序在文件 PROG1.C 中,请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 文件 PROG1.C 内容如下: #includestdio.h void fun(int m,int *k,int xx) void mainU /U int m,n,zz100; printf(“/nPlease enter an integer nu

12、mber between 10 and 100:“); scanf(“%d“, )解析:解析 本题虽然是要求求出非素数,实际也是考查素数的判定算法。对于变量 i 取出的每一个值,变量 j 都从 2 开始循环到 i/2,在变量 j 的这个范围内,能找到一个 j,i 能够整除它,则 i 是非素数,将 i 赋值到数组 xx 中。循环结束后,将数组的长度 n 赋值给*k,通过指针 k 带回数组 xx 的长度。 归纳总结 本套试题的程序填空和程序设计题考查的是素数的判定算法。考题中通常要求对某个范围内的素数进行一定的处理。此类题目的常用程序段如下: for(i=m;i=n;i+) /*求出 m 到 n 之间的素数*/ for(j=2;j=i/2;j+) if(i%j=0)break; if(ji/2) /*若条件成立,则 i 是素数,根据程序要求补充后面的语句*/

展开阅读全文
相关资源
猜你喜欢
  • BS ISO 8254-3-2016 Paper and board Measurement of specular gloss 20 gloss with a converging beam TAPPI method《纸和纸板 光泽度的测量 用聚光束的20光泽度的TAPPI法》.pdf BS ISO 8254-3-2016 Paper and board Measurement of specular gloss 20 gloss with a converging beam TAPPI method《纸和纸板 光泽度的测量 用聚光束的20光泽度的TAPPI法》.pdf
  • BS ISO 8260-2008 Milk and milk products - Determination of organochlorine pesticides and polychlorobiphenyls - Method using capillary gas-liquid chromatography with electron- captu.pdf BS ISO 8260-2008 Milk and milk products - Determination of organochlorine pesticides and polychlorobiphenyls - Method using capillary gas-liquid chromatography with electron- captu.pdf
  • BS ISO 8262-1-2006 Milk products and milk-based foods - Determination of fat content by the Weibull-Berntrop gravimetric method (reference method) - Infant foods《乳制品和以乳为基料的食品 用维泊尔-.pdf BS ISO 8262-1-2006 Milk products and milk-based foods - Determination of fat content by the Weibull-Berntrop gravimetric method (reference method) - Infant foods《乳制品和以乳为基料的食品 用维泊尔-.pdf
  • BS ISO 8262-2-2006 Milk products and milk-based foods - Determination of fat content by the Weibull-Berntrop gravimetric method (reference method) - Edible ices and ice-mixes《乳制品和以.pdf BS ISO 8262-2-2006 Milk products and milk-based foods - Determination of fat content by the Weibull-Berntrop gravimetric method (reference method) - Edible ices and ice-mixes《乳制品和以.pdf
  • BS ISO 8262-3-2006 Milk products and milk-based foods - Determination of fat content by the Weibull-Berntrop gravimetric method (Reference method) - Special cases《乳制品和以乳为基料的食品 用维泊尔.pdf BS ISO 8262-3-2006 Milk products and milk-based foods - Determination of fat content by the Weibull-Berntrop gravimetric method (Reference method) - Special cases《乳制品和以乳为基料的食品 用维泊尔.pdf
  • BS ISO 8279-2008 Aerospace - Nuts hexagonal plain normal height normal across flats with MJ threads classifications 600 MPa (at ambient temperature) 120 C 600 MPa (at ambient tempe.pdf BS ISO 8279-2008 Aerospace - Nuts hexagonal plain normal height normal across flats with MJ threads classifications 600 MPa (at ambient temperature) 120 C 600 MPa (at ambient tempe.pdf
  • BS ISO 8297-1995 Acoustics - Determination of sound power levels of multisource industrial plants for evaluation of sound pressure levels in the environment - Engineering method《声学.pdf BS ISO 8297-1995 Acoustics - Determination of sound power levels of multisource industrial plants for evaluation of sound pressure levels in the environment - Engineering method《声学.pdf
  • BS ISO 830-1999 Freight containers - Vocabulary《货运集装箱 词汇》.pdf BS ISO 830-1999 Freight containers - Vocabulary《货运集装箱 词汇》.pdf
  • BS ISO 8310-2012 Refrigerated hydrocarbon and non-petroleum based liquefied gaseous fuels General requirements for automatic tank thermometers on board marine carriers and floating.pdf BS ISO 8310-2012 Refrigerated hydrocarbon and non-petroleum based liquefied gaseous fuels General requirements for automatic tank thermometers on board marine carriers and floating.pdf
  • 相关搜索

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

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