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

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

1、二级 C 语言-391 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:根据形参 i 的值返回某个函数的值。当调用正确时,程序输出: x1=5.000000,x2=3.000000,x1*x1+x1*x2=40.000000。 注意:不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h double f1(double x) return x*x; double f2(double x,double y) return x*y; /*found*/ 1fun(int i,d

2、ouble x,double y) if(i=1) /*found*/ return 2(x); else /*found*/ return 3(x,y); main() double x1=5,x2=3,r; r=fun(1,x1,x2); r+=fun(2,x1,x2); printf(“/nx1=%f,x2=%f,x1*x1+x1*x2=%f/n/n“,x1,x2,r); (分数:30.00)二、程序修改题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:比较两个字符串,将长的字符串的首地址作为函数值返回。 请改正程序中的错误,使它能得出正确的结果。 注意:不要

3、改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includeconio.h #includestdio.h /*found*/ double fun(char*s,char*t) int s1=0,t1=0; char*ss,*tt; ss=s; tt=t; while(*ss) s1+; /*found*/ (*ss)+; while(*tt) t1+; /*found*/ (*tt)+; if(t1s1) return t; else return s; void main() char a80,b80; printf(“/nEnter a string:“)

4、 gets(a); printf(“/nEnter a string again:“); gets(b); printf(“/nThe longer is:/n/n%s/n“,fun(a,b); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写函数 fun,其功能是:移动字符串中的内容,移动的规则是把第 1m 个字符,平移到字符串的最后,把第 m+1 到最后的字符移到字符串的前部。 例如,字符串中原有的内容为“ABCDEFGHIJK“,m 的值为 3,移动后,字符串中的内容应该是“DEFGHIJKABC“。 注意:请勿改动 main 函数和其他函数中的任何内容,仅

5、在函数 fun 的花括号中填入你编写的若干语句。 试题程序: #includestdio.h #includestring.h #define N 80 void fun(char*w,int m) void main() FILE*wf; char aN=“ABCDEFGHIJK“,bN=“ABCDEFGHIJK“; int m; printf(“The origina string:/n“); puts(a); printf(“/n/nEnter m:“); scanf(“%d“, fun(a,m); printf(“/nThe string after moving:/n“); puts

6、a); printf(“/n/n“); /*found*/ wf=fopen(“out.dat“,“w“); fun(b,3); fprintf(wf,“%s“,b); fclose(wf); /*found*/ (分数:40.00)_二级 C 语言-391 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:根据形参 i 的值返回某个函数的值。当调用正确时,程序输出: x1=5.000000,x2=3.000000,x1*x1+x1*x2=40.000000。 注意:不得增行或删行,也不得更改程序的结构!

7、 试题程序: #includestdio.h double f1(double x) return x*x; double f2(double x,double y) return x*y; /*found*/ 1fun(int i,double x,double y) if(i=1) /*found*/ return 2(x); else /*found*/ return 3(x,y); main() double x1=5,x2=3,r; r=fun(1,x1,x2); r+=fun(2,x1,x2); printf(“/nx1=%f,x2=%f,x1*x1+x1*x2=%f/n/n“,x

8、1,x2,r); (分数:30.00)解析:(1)double (2)f1 (3)f2 解析 填空 1:本空函数 fun 的返回值,根据 return 可知,不论返回的是 f1 还是 f2,它们的返回值均为double 型的,故此空应该填写 double。 填空 2:因为函数 fun 的功能是根据形参 i 的值返回某个函数的值,当 i 等于 1 时,应该返回的是 f1。 填空 3:如果不满足 if 的话,应该返回的是 f2。二、程序修改题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:比较两个字符串,将长的字符串的首地址作为函数值返回。 请改正程序中的错误,使它能得

9、出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includeconio.h #includestdio.h /*found*/ double fun(char*s,char*t) int s1=0,t1=0; char*ss,*tt; ss=s; tt=t; while(*ss) s1+; /*found*/ (*ss)+; while(*tt) t1+; /*found*/ (*tt)+; if(t1s1) return t; else return s; void main() char a80,b80; printf(“/nEnte

10、r a string:“); gets(a); printf(“/nEnter a string again:“); gets(b); printf(“/nThe longer is:/n/n%s/n“,fun(a,b); (分数:30.00)解析:(1)char*fun(char*s,char*t) (2)ss+; (3)tt+; 解析 (1)在主函数的输出语句中,函数:fun 是以字符串格式输出的,所以定义函数时应为char*fun(char*s,char*t)。 (2)和(3)这里是地址加 1,而不是内容加 1,所以改为 ss+和 tt+。三、程序设计题(总题数:1,分数:40.00)3

11、请编写函数 fun,其功能是:移动字符串中的内容,移动的规则是把第 1m 个字符,平移到字符串的最后,把第 m+1 到最后的字符移到字符串的前部。 例如,字符串中原有的内容为“ABCDEFGHIJK“,m 的值为 3,移动后,字符串中的内容应该是“DEFGHIJKABC“。 注意:请勿改动 main 函数和其他函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 试题程序: #includestdio.h #includestring.h #define N 80 void fun(char*w,int m) void main() FILE*wf; char aN=“ABC

12、DEFGHIJK“,bN=“ABCDEFGHIJK“; int m; printf(“The origina string:/n“); puts(a); printf(“/n/nEnter m:“); scanf(“%d“, fun(a,m); printf(“/nThe string after moving:/n“); puts(a); printf(“/n/n“); /*found*/ wf=fopen(“out.dat“,“w“); fun(b,3); fprintf(wf,“%s“,b); fclose(wf); /*found*/ (分数:40.00)_正确答案:()解析:void fun(char*w,int m) int i,j; char t; for(i=1;i=m;i+)/*进行 m 次的循环左移*/ t=w0; for(j=1;wj!=“/0“;j+)/*从第 2 个字符开始以后的每个字符都依次前移一个字符*/ wj-1=wj; wj-1=t;/*将第 1 个字符放到最后一个字符中*/ 解析 本题应采用“循环左移”的算法,多层循环用于控制移动的字符的个数,即需进行多少次循环,内嵌循环的作用是将从第 2 个字符以后的每个字符依次前移一个位置,最后将第 1 个字符放到最后一个字符中。

展开阅读全文
相关资源
猜你喜欢
  • EN 1457-1-2012 en Chimneys - Clay ceramic flue liners - Part 1 Flue liners operating under dry conditions - Requirements and test methods《烟囱-粘土 陶瓷烟道内衬-第1部分 烟道内衬在干燥条件下操作 要求和测试方法(取代 .pdf EN 1457-1-2012 en Chimneys - Clay ceramic flue liners - Part 1 Flue liners operating under dry conditions - Requirements and test methods《烟囱-粘土 陶瓷烟道内衬-第1部分 烟道内衬在干燥条件下操作 要求和测试方法(取代 .pdf
  • EN 1457-2-2012 en Chimneys - Clay ceramic flue liners - Part 2 Flue liners operating under wet conditions - Requirements and test methods《烟囱 粘土 陶瓷烟道内衬 第2部分 烟道内衬在湿润条件下操作 要求和试验方法》.pdf EN 1457-2-2012 en Chimneys - Clay ceramic flue liners - Part 2 Flue liners operating under wet conditions - Requirements and test methods《烟囱 粘土 陶瓷烟道内衬 第2部分 烟道内衬在湿润条件下操作 要求和试验方法》.pdf
  • EN 1458-1-2011 en Domestic direct gas-fired tumble dryers of types B22D and B23D of nominal heat input not exceeding 6 kW - Part 1 Safety《额定热输入值不超过6KW型号为B22D和B23D的家用直接燃气滚筒式烘干机 安全性》.pdf EN 1458-1-2011 en Domestic direct gas-fired tumble dryers of types B22D and B23D of nominal heat input not exceeding 6 kW - Part 1 Safety《额定热输入值不超过6KW型号为B22D和B23D的家用直接燃气滚筒式烘干机 安全性》.pdf
  • EN 1458-2-2011 en Domestic direct gas-fired tumble dryers of types B22D and B23D of nominal heat input not exceeding 6 kW - Part 2 Rational use of energy《标称热输入不超过6kW的B和B型家用直接燃气式滚筒干.pdf EN 1458-2-2011 en Domestic direct gas-fired tumble dryers of types B22D and B23D of nominal heat input not exceeding 6 kW - Part 2 Rational use of energy《标称热输入不超过6kW的B和B型家用直接燃气式滚筒干.pdf
  • EN 1459-1-2017 en Rough-terrain trucks - Safety requirements and verification - Part 1 Variable-reach trucks.pdf EN 1459-1-2017 en Rough-terrain trucks - Safety requirements and verification - Part 1 Variable-reach trucks.pdf
  • EN 1459-1998 en Safety of industrial trucks - Self-propelled variable reach trucks (Incorporates Amendment A3 2012 Remains Current)《工业用卡车的安全 自推式可变延伸卡车 包含修改件A2-2010》.pdf EN 1459-1998 en Safety of industrial trucks - Self-propelled variable reach trucks (Incorporates Amendment A3 2012 Remains Current)《工业用卡车的安全 自推式可变延伸卡车 包含修改件A2-2010》.pdf
  • EN 1459-2-2015 en Rough-terrain trucks - Safety requirements and verification - Part 2 Slewing variable-reach trucks《越野车 安全要求和验证 第2部分 回转可变前移式叉车》.pdf EN 1459-2-2015 en Rough-terrain trucks - Safety requirements and verification - Part 2 Slewing variable-reach trucks《越野车 安全要求和验证 第2部分 回转可变前移式叉车》.pdf
  • EN 1459-3-2015 en Rough-terrain trucks - Safety requirements and verification - Part 3 Interface between the variable-reach truck and the work platform《越野车 安全要求和验证 第3部分 可变前移式叉车和工作平.pdf EN 1459-3-2015 en Rough-terrain trucks - Safety requirements and verification - Part 3 Interface between the variable-reach truck and the work platform《越野车 安全要求和验证 第3部分 可变前移式叉车和工作平.pdf
  • EN 1462-2004 en Brackets for Eaves Gutters - Requirements and Testing《檐沟撑架 要求和检验》.pdf EN 1462-2004 en Brackets for Eaves Gutters - Requirements and Testing《檐沟撑架 要求和检验》.pdf
  • 相关搜索

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

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