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

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

1、二级 C 语言机试-243 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)字符串 str 由数字字符组成(长度不超过 5 个字符),可看做任意进制的数,请补充函数 proc(),该函数的功能是:把 str 字符串从二进制转换为十进制的数,结果保存在数组 xx 中,由函数返回转换后数组 xx的实际长度。其中 x 表示 str 原来的进制,y 表示要转换成的进制。例如,输入 str=“1011“, x=2,y=10,结果输出:11。注意:部分源程序已给出。请勿改动主函数 main 和其他函数中的任何内容。试题程序:#includestdio.h#i

2、ncludestdlib.h#includestring.h#define M 8int xxM;int proc(char*str, int x, int y)int sum;int i=0;char *p=str;for(i=0; iM; i+)xxi=0;sum= (1) ;p+;while(*p)sum=sum*x+*p-0;p+;i=0;while(sum!=0)xxi= (2) ;(3) ;i+;return i;void main()char str6;int i;int n;int x;int y;printf(“Enter a string made up of 0 to 9

3、 digits character: “);gets(str);if(strlen(Str)5)printf(“Error: string too longer!, please input again!/n/n“);exit(0);for(i=0; slri; i+)if(stri0|stri9)printf(“Error: %c not is 0to 9 digits character! /n/n“, stri);exit(0);printf(“The original string: “);puts(str);printf(“/nINPUT x=“);scanf(“%d“, print

4、f(“/nINPUT y=“);scanf(“%d“, n=proc(str, X, y);printf(“/n%s is convered to“, str);for(i=n=1; i=0; i-)printf(“%d/n“, xxi/n);(分数:30.00)填空项 1:_填空项 1:_填空项 1:_二、改错题(总题数:1,分数:30.00)1.下列给定程序中,函数 proc()的功能是:根据整型形参 n 的值,计算如下公式的值。t=1-1/(22)-1/(33)-1/(nn)例如,当 n=7 时,t=0.488203。请修改函数 proc()中的错误,使它能得出正确的结果。注意:不要改动

5、 main()函数,不得增行或删行,也不得更改程序的结构。试题程序:#includestdlib.h#includeconio.h#includestdio.hdouble proc(int n)double y=1.0;int i;/*found*for(i=2; in; i+)/*found*y-=1/(i*i);return(y);void main()int n=7;system(“CLS“);printf(“/nThe result is %1f/n“, proc(n);(分数:30.00)填空项 1:_三、编程题(总题数:1,分数:40.00)2.M 名学生的成绩已在主函数中放入一

6、个带头结点的链表结构中,h 指向链表的头结点。请编写函数proc(),它的功能是:找出学生的最高分,由函数值返回。注意:部分源程序已给出。请勿改动主函数 main 和其他函数中的任何内容。试题程序:#includestdio.h#includestdlib.h#define M 8struet slistdouble s;struct slist * next;typedef struct slist STREC;double proc(STREC * h)STREC*treat(double*s)STREC *h, *p, *q;int i=0;h=p=(STREC*)malloc(size

7、of(STREC);p-s=0;while(iM)/产生 8 个结点的链表,各分数存入链表中q=(STREC*)malloc(sizeof(STREC);p-s=sei; i+; p-next=q; p=q;p-next=NULL;return h; /返回链表的首地址void outlist(STREC*h)STREC *p;p=h;printf(“head“);doprintf(“-%2.Of“, p-s); p=p-next;/输出各分数while(p-next! =NULL);printf(“n/n“);void main()double stuM=60, 70, 80, 90, 65

8、, 75, 85, 95,max;STREC *h;h=creat(stu);outlist(h);max=proc(h);printf(“max=%6.1f/n“, max);(分数:40.00)_二级 C 语言机试-243 答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)字符串 str 由数字字符组成(长度不超过 5 个字符),可看做任意进制的数,请补充函数 proc(),该函数的功能是:把 str 字符串从二进制转换为十进制的数,结果保存在数组 xx 中,由函数返回转换后数组 xx的实际长度。其中 x 表示 str 原来的进制,y 表示要转换

9、成的进制。例如,输入 str=“1011“, x=2,y=10,结果输出:11。注意:部分源程序已给出。请勿改动主函数 main 和其他函数中的任何内容。试题程序:#includestdio.h#includestdlib.h#includestring.h#define M 8int xxM;int proc(char*str, int x, int y)int sum;int i=0;char *p=str;for(i=0; iM; i+)xxi=0;sum= (1) ;p+;while(*p)sum=sum*x+*p-0;p+;i=0;while(sum!=0)xxi= (2) ;(3)

10、 ;i+;return i;void main()char str6;int i;int n;int x;int y;printf(“Enter a string made up of 0 to 9 digits character: “);gets(str);if(strlen(Str)5)printf(“Error: string too longer!, please input again!/n/n“);exit(0);for(i=0; slri; i+)if(stri0|stri9)printf(“Error: %c not is 0to 9 digits character! /n

11、/n“, stri);exit(0);printf(“The original string: “);puts(str);printf(“/nINPUT x=“);scanf(“%d“, printf(“/nINPUT y=“);scanf(“%d“, n=proc(str, X, y);printf(“/n%s is convered to“, str);for(i=n=1; i=0; i-)printf(“%d/n“, xxi/n);(分数:30.00)填空项 1:_ (正确答案:sum*x+*p-0)解析:填空项 1:_ (正确答案:sum%y)解析:填空项 1:_ (正确答案:sum=

12、sum/y)解析:解析 要完成程序所要求的功能,首先要将字符串转换为 int 型的数据,因此1填 sum*x+*p-0;然后再将变量 sum 转换为所需要的类型。因此,2填 sum%y,3填 sum=sum/y。二、改错题(总题数:1,分数:30.00)1.下列给定程序中,函数 proc()的功能是:根据整型形参 n 的值,计算如下公式的值。t=1-1/(22)-1/(33)-1/(nn)例如,当 n=7 时,t=0.488203。请修改函数 proc()中的错误,使它能得出正确的结果。注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。试题程序:#includestdli

13、b.h#includeconio.h#includestdio.hdouble proc(int n)double y=1.0;int i;/*found*for(i=2; in; i+)/*found*y-=1/(i*i);return(y);void main()int n=7;system(“CLS“);printf(“/nThe result is %1f/n“, proc(n);(分数:30.00)填空项 1:_ (正确答案:(1)错误:for(i=2; in; i+) 正确:for(i=2; i=n; i+)(2)错误:y-=1/(i*i); 正确:y-=1.0/(i*i);)解析

14、:解析 根据题目中所给公式 t=1-1/(22)一 1/(33)-1/(nn),可知需要循环至 i=n。因此,for(i=2; in; i+)应改为 for(i=2; i=n; i+);根据 C 语言中的语法规则,整数与整数相除结果仍为整数,要得到浮点数在分数中分子或分母最少有一个是浮点数。因此,y-=1/(i*i);应改为y=1.0/(i*i)。三、编程题(总题数:1,分数:40.00)2.M 名学生的成绩已在主函数中放入一个带头结点的链表结构中,h 指向链表的头结点。请编写函数proc(),它的功能是:找出学生的最高分,由函数值返回。注意:部分源程序已给出。请勿改动主函数 main 和其他

15、函数中的任何内容。试题程序:#includestdio.h#includestdlib.h#define M 8struet slistdouble s;struct slist * next;typedef struct slist STREC;double proc(STREC * h)STREC*treat(double*s)STREC *h, *p, *q;int i=0;h=p=(STREC*)malloc(sizeof(STREC);p-s=0;while(iM)/产生 8 个结点的链表,各分数存入链表中q=(STREC*)malloc(sizeof(STREC);p-s=sei;

16、 i+; p-next=q; p=q;p-next=NULL;return h; /返回链表的首地址void outlist(STREC*h)STREC *p;p=h;printf(“head“);doprintf(“-%2.Of“, p-s); p=p-next;/输出各分数while(p-next! =NULL);printf(“n/n“);void main()double stuM=60, 70, 80, 90, 65, 75, 85, 95,max;STREC *h;h=creat(stu);outlist(h);max=proc(h);printf(“max=%6.1f/n“, max);(分数:40.00)_正确答案:(double proc (STREC *h)double max=h-s; while (h!=NULL) /判断其是否为终结点if (maxh=s)max=h-s; /把大的数放到 max 中h=h-next;return max; /最后通过返回值返回到主函数中)解析:解析 要找出学生的最高分,要比较所有学生的成绩。定义一个变量 max 用来存放学生的最高分初始化为第一个学生的成绩,依次与其后的学生成绩相比较,最后将得到的最高分返回主函数。

展开阅读全文
相关资源
猜你喜欢
相关搜索

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

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