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

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

1、二级 C 语言-361 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 fun()函数,该函数的功能是:把字符的 ASCII 码中为奇数的字符从字符串 str 中删除,结果仍然保存在字符串 str 中,字符串 str 从键盘输入,其长度作为参数传入 fun()函数。 例如,输入“abcdef”,则输出“bdf”。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #define N 100 v

2、oid 1 int i,j; 2; for(i=0;in;i+) if(si%2=0) sj+=si; 3; void main() int i=0,len=0; char strN; printf(“please input a string:/n“); gets(str); while(stri!=“/0“) len+; i+; fun(str,len); printf(“The result string:/n“); puts(str); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:计算函数 F(x,y,z)=(x+v)

3、/(x-y)+(z+y)/(z-y)的值。其中 x和 y 的值不相等,z 和 y 的值不相等。例如,当 x 的值为 1,y 的值为 2,z 的值为 3 时,函数值为 2.00。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdio.h #includestdio.h /*found* #define F(m,n)(m/n) float fun(float a,float b,float c) float s; s=F(a+b),(a-b)+F(c+b),(c-b); /*found* Return(s); void main() fl

4、oat x,y,z,sum; printf(“input x y z:“); scanf(“%f%f%f“, printf(“x=%f,y=%f,z=%f/n“,x,y,z); if(x=y|y=z) printf(“Data error!/n“); exit(0); sum=fun(x,y,z) printf(“the result is:%5.2f/n“,sum); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.编写一个函数,输入 n 个字符串,串与串之间以 Enter 键分隔,找出最短字符串中第一个字符串,传回该串地址(用一个新串“*”作为结束输入的标志)。 注意

5、部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 fun()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includestring.h #includeconio.h char*fun(char(*s)100,int num) void main() char str10100,*min; int n,i=0; FILE*out;printf(“input strings with“*“ as end:“); gets(stri); puts(stri); while(!strcmp(stri,“*“)=0) i+; get

6、s(stri); puts(stri); n=1; min=fun(str,n); printf(“/nmin=%s/n“,min); out=fopen(“outfile.dat“,“w“); strcpy(str0,“just,“); strcpy(str1,“a“); strcpy(str2,“test“); strcpy(str3,“some“); strcpy(str4,“tool?!?“); fprintf(out,“%s“,fun(str,5); fclose(out); (分数:40.00)_二级 C 语言-361 (1)答案解析(总分:100.00,做题时间:90 分钟)一、

7、程序填空题(总题数:1,分数:30.00)1.请补充 fun()函数,该函数的功能是:把字符的 ASCII 码中为奇数的字符从字符串 str 中删除,结果仍然保存在字符串 str 中,字符串 str 从键盘输入,其长度作为参数传入 fun()函数。 例如,输入“abcdef”,则输出“bdf”。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #define N 100 void 1 int i,j; 2; for(i=0;in;i+) if(si%2=0)

8、sj+=si; 3; void main() int i=0,len=0; char strN; printf(“please input a string:/n“); gets(str); while(stri!=“/0“) len+; i+; fun(str,len); printf(“The result string:/n“); puts(str); (分数:30.00)解析:fun(char s,int n) j=0 sj=“/0“ 解析 先判断 ASCII 码的奇偶。 第一空:根据主函数“fun(str,len);”调用语句,其中 len 为字符串 str 的长度,用来控制循环。根

9、据主函数中对应的调用语句,补全 fun()函数定义,第一空填“fun(char s,int n)”。 第二空:“sj+=si;”语句中 j 的变量在使用前要对其取值进行初始化,因为数组下标是由 0 开始的,初始化值为 0,所以第二空填“j=0”。 第三空:新生成的字符串要加尾符标志,所以第三空填“sj=“/0“”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:计算函数 F(x,y,z)=(x+v)/(x-y)+(z+y)/(z-y)的值。其中 x和 y 的值不相等,z 和 y 的值不相等。例如,当 x 的值为 1,y 的值为 2,z 的值为 3 时

10、函数值为 2.00。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdio.h #includestdio.h /*found* #define F(m,n)(m/n) float fun(float a,float b,float c) float s; s=F(a+b),(a-b)+F(c+b),(c-b); /*found* Return(s); void main() float x,y,z,sum; printf(“input x y z:“); scanf(“%f%f%f“, printf(“x=%f,y=%f,z=%f

11、/n“,x,y,z); if(x=y|y=z) printf(“Data error!/n“); exit(0); sum=fun(x,y,z) printf(“the result is:%5.2f/n“,sum); (分数:30.00)解析:错误:#define F(m,n)(m/n) 正确:#define F(m,n)(m)/(n) 错误:Return(s); 正确:return(s); 解析 程序中函数的功能是计算题目中给出的公式值,第一个标识:fun()函数两次调用宏 F 来计算“s=F(a+b),(a-b)+F(c+b),(c-b);”。检查宏的定义是否正确,可以用实参代入宏进行展

12、开:并非(a+b)/(a-b),而是(a+b/a-b),因为“/”的优先级高于“+”或“-”,所以要使用括号限定汁算优先顺序。所以将“#define F(m,n)(m/n)”改为“#define F(m,n)(m)/(n)”。 第二个标识下返回语句的关键字有误。因为 C 语言中区分大小写,所以应将“Return(s);”改成“return(s);”。三、程序设计题(总题数:1,分数:40.00)3.编写一个函数,输入 n 个字符串,串与串之间以 Enter 键分隔,找出最短字符串中第一个字符串,传回该串地址(用一个新串“*”作为结束输入的标志)。 注意:部分源程序给出如下。 请勿改动 main

13、)函数和其他函数中的任何内容,仅在函数 fun()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includestring.h #includeconio.h char*fun(char(*s)100,int num) void main() char str10100,*min; int n,i=0; FILE*out;printf(“input strings with“*“ as end:“); gets(stri); puts(stri); while(!strcmp(stri,“*“)=0) i+; gets(stri); puts(stri);

14、n=1; min=fun(str,n); printf(“/nmin=%s/n“,min); out=fopen(“outfile.dat“,“w“); strcpy(str0,“just,“); strcpy(str1,“a“); strcpy(str2,“test“); strcpy(str3,“some“); strcpy(str4,“tool?!?“); fprintf(out,“%s“,fun(str,5); fclose(out); (分数:40.00)_正确答案:()解析:int i; char*min; min=s0;/min 初始化 for(i=0;inum;i+) if(strlen(min)strlen(si)/min 指向的字符串与其他的字符串长度进行比较 min=si; return min;/返回最小值的字符串 解析 首先指定第一个字符串为长度最小的字符串,然后在循环过程中将其与其他的所有串的长度进行比较,求出最小的串。设置一个指针变量 min,使它的初值为第一个字符串,再使其他的所有串的长度与 min 的长度进行比较,若其他字符串的长度小于 min,则将其他字符串的首地址赋值给 min。最后使用返回语句,返回最短长度 min 的字符串的地址。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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