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

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

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

2、入所编写的若干表达式或语句。 试题程序: #includestdio.h #includestdlib.h #includestring.h #define M 8 int 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;

3、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;stri;i+) if(stri“0“|stri“9“) printf(“Error:%c not is“0“to“9“ digits character!/n/n“,stri); exit(0); printf(“The origina

4、l 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,分数:30.00)2.下列给定程序中,函数 proc()的功能是:根据整型形参 n 的值,计算如下公式的值。 t=1-1/(2*2)-1/(3*3)-1/(n*n) 例如,当 n=7

5、时,t=0.488203。 请修改函数 proc()中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h double 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“,pro

6、c(n); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.M 名学生的成绩已在主函数中放入一个带头结点的链表结构中,h 指向链表的头结点。请编写函数proc(),它的功能是:找出学生的最高分,由函数值返回。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includestdlib.h #define M 8 struct slist double s; struct slist * next; ; typedef struct slist

7、 STREC; double proc(STREC*h) STREC*creat(double*s) STREC*h,*p,*q; int i=0; h=p=(STREC*)malloc(sizeof(STREC); p-s=0; while(iM) /产生 8 个结点的链表,各分数存入链表中 q=(STREC*)maUoc(sizeof(STREC); p-s=si;i+;p-next=q;p=q; p-next=NULL。 return h;/返回链表的首地址 void outlist(STREC*h) STREC*p; p=h; print(“head“); do printf(“-%2

8、0f“,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)_二级 C 语言-391 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.字符串 str 由数字字符组成(长度不超过 5 个字符),可

9、看作任意进制的数,请补充函数 proc(),该函数的功能是:把 str 字符串从二进制转换成十进制的数,结果保存在数组 xx 中,由函数返回转换后数组xx 的实际长度。其中 x 表示 str 原来的进制,y 表示要转换成的进制。例如,输入str=“1011“,x=2,y=10,结果输出 11。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #includestdlib.h #includestring.h #define M 8 int xxM; int p

10、roc(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“digits character:“); gets(str); if(strlen(

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

12、c(str,x,y); printf(“/n%s is convered to“,str); for(i=n-1;i=0;i-) printf(“%d/n“,xxi/n); (分数:30.00)解析:sum*x+*p-“0“ sum%y sum=sum/y解析 要完成程序所要求的功能,首先要将字符串转换为 int 型的数据,因此,第一处填“sum*x+*p-“0“”;然后再将变量 sum 转换为所需要的类型,因此,第二处填“sum%y”,第三处填“sum=sum/y”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:根据整型形参 n 的值,计算如下

13、公式的值。 t=1-1/(2*2)-1/(3*3)-1/(n*n) 例如,当 n=7 时,t=0.488203。 请修改函数 proc()中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h double 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; syste

14、m(“CLS“); printf(“/nThe result is%1f/n“,proc(n); (分数:30.00)解析:错误:for(i=2;in;i+) 正确:for(j=2;i=n;i+) 错误:y-=1/(i*i); 正确:y-=1.0/(i*i); 解析 根据题目中所给公式 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.

15、0/(i*i);”。三、程序设计题(总题数:1,分数:40.00)3.M 名学生的成绩已在主函数中放入一个带头结点的链表结构中,h 指向链表的头结点。请编写函数proc(),它的功能是:找出学生的最高分,由函数值返回。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includestdlib.h #define M 8 struct slist double s; struct slist * next; ; typedef struct slist STREC

16、 double proc(STREC*h) STREC*creat(double*s) STREC*h,*p,*q; int i=0; h=p=(STREC*)malloc(sizeof(STREC); p-s=0; while(iM) /产生 8 个结点的链表,各分数存入链表中 q=(STREC*)maUoc(sizeof(STREC); p-s=si;i+;p-next=q;p=q; p-next=NULL。 return h;/返回链表的首地址 void outlist(STREC*h) STREC*p; p=h; print(“head“); do printf(“-%2.0f“,p

17、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 用来存放学生的最高分,初始化为第一个学生的成绩,依次与其后的学生成绩相比较,最后将得到的最高分返回主函数。

展开阅读全文
相关资源
猜你喜欢
  • ISO 8524-1986 Equipment for distributing granulated pesticides or herbicides Test method《颗粒杀虫剂或除草剂撒布机试验方法》.pdf ISO 8524-1986 Equipment for distributing granulated pesticides or herbicides Test method《颗粒杀虫剂或除草剂撒布机试验方法》.pdf
  • ISO 8526-1-1990 Modular units for machine tools workholding pallets part 1 workholding pallets up to 800 mm nominal size《组合机床通用部件 工件夹持托板 第1部分 名义尺寸至800mm的工件夹持托板》.pdf ISO 8526-1-1990 Modular units for machine tools workholding pallets part 1 workholding pallets up to 800 mm nominal size《组合机床通用部件 工件夹持托板 第1部分 名义尺寸至800mm的工件夹持托板》.pdf
  • ISO 8526-2-1990 Modular units for machine tools workholding pallets part 2 workholding pallets of nominal size greater than 800 mm《组合机床通用部件 工件夹持托板 第2部分 名义尺寸大于80.pdf ISO 8526-2-1990 Modular units for machine tools workholding pallets part 2 workholding pallets of nominal size greater than 800 mm《组合机床通用部件 工件夹持托板 第2部分 名义尺寸大于80.pdf
  • ISO 8528-10-1998 Reciprocating internal combustion engine driven alternating current generating sets - Part 10 Measurement of airborne noise by the enveloping s.pdf ISO 8528-10-1998 Reciprocating internal combustion engine driven alternating current generating sets - Part 10 Measurement of airborne noise by the enveloping s.pdf
  • ISO 8528-12-1997 Reciprocating internal combustion engine driven alternating current generating sets - Part 12 Emergency power supply to safety services《往复式内燃交流.pdf ISO 8528-12-1997 Reciprocating internal combustion engine driven alternating current generating sets - Part 12 Emergency power supply to safety services《往复式内燃交流.pdf
  • ISO 8528-3-2005 Reciprocating internal combustion engine driven alternating current generating sets - Part 3 Alternating current generators for generating sets《.pdf ISO 8528-3-2005 Reciprocating internal combustion engine driven alternating current generating sets - Part 3 Alternating current generators for generating sets《.pdf
  • ISO 8528-4-2005 Reciprocating internal combustion engine driven alternating current generating sets - Part 4 Controlgear and switchgear《往复式内燃交流发电机组 第4部分 控制装置与开关.pdf ISO 8528-4-2005 Reciprocating internal combustion engine driven alternating current generating sets - Part 4 Controlgear and switchgear《往复式内燃交流发电机组 第4部分 控制装置与开关.pdf
  • ISO 8528-6-2005 Reciprocating internal combustion engine driven alternating current generating sets - Part 6 Test methods《往复式内燃交流发电机组 第6部分 试验方法》.pdf ISO 8528-6-2005 Reciprocating internal combustion engine driven alternating current generating sets - Part 6 Test methods《往复式内燃交流发电机组 第6部分 试验方法》.pdf
  • ISO 8529-2-2000 Reference neutron radiations - Part 2 Calibration fundamentals of radiation protection devices related to the basic quantities characterizing th.pdf ISO 8529-2-2000 Reference neutron radiations - Part 2 Calibration fundamentals of radiation protection devices related to the basic quantities characterizing th.pdf
  • 相关搜索

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

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