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

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

1、二级 C 语言-389 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.str 是一个由数字和字母字符组成的字符串,由变量 num 传入字符串长度。请补充函数 proc(),该函数的功能是:把字符串 str 中的数字字符转换成数字并存放到整型数组 bb 中,函数返回数组 bb 的长度。 例如,str=“abc123de45fg67“,结果为 1234567。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdi

2、o.h #define M 80 int bbM; int proc(char str,int bb,int num) int i,n=0; for(i=0;inum;i+) if( 1) bbn= 2; n+; return 3; vnid main() char strM; int num=0,n,i; printf(“Enter a string:n“); gets(str); while(strnum) num+; n=proc(str,bb,num); printf(“/nbb=“); for(i=0;in;i+) printf(“%d“,bbi); (分数:30.00)二、程序改错

3、题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:读入一个字符串(长度20),将该字符串中的所有字符按ASCII 码升序排序后输出。 例如,输入 opdye,则应输出 deopy。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestring.h #includestdlib.h #includeconio.h #includestdio.h /*found* int proc(char str) char c; unsigned i,j; for(i=0;istrl

4、en(str)-1;i+) for(j=i+1;jstrlen(str);j+) if(stristrj) c=strj; |*found* strj=stri+; stri=c; void main() char str81; system(“CLS“): printf(“/nPlease enter a character string:“); gets(str); printf(“/n/nBefore sorting:/n%S“,str); proc(str); printf(“/nAfter sorting decendingly:n%S“,str); (分数:30.00)三、程序设计

5、题(总题数:1,分数:40.00)3.请编写函数 proc(),它的功能是计算: s=(ln(1)+ln(2)+ln(3)+ln(m)0.5 在 C 语言中可调用 log(n)函数求 ln(n)。 例如,若 m 的值为 30,则 proc()函数值为 8.640500。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h #includemath.h double proc(int m) void mai

6、n() system(“CLS“); printf(“%f/n“,proc(30); (分数:40.00)_二级 C 语言-389 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.str 是一个由数字和字母字符组成的字符串,由变量 num 传入字符串长度。请补充函数 proc(),该函数的功能是:把字符串 str 中的数字字符转换成数字并存放到整型数组 bb 中,函数返回数组 bb 的长度。 例如,str=“abc123de45fg67“,结果为 1234567。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任

7、何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #define M 80 int bbM; int proc(char str,int bb,int num) int i,n=0; for(i=0;inum;i+) if( 1) bbn= 2; n+; return 3; vnid main() char strM; int num=0,n,i; printf(“Enter a string:n“); gets(str); while(strnum) num+; n=proc(str,bb,num); printf(“/nbb=

8、); for(i=0;in;i+) printf(“%d“,bbi); (分数:30.00)解析:stri=“0“ unsigned i,j; for(i=0;istrlen(str)-1;i+) for(j=i+1;jstrlen(str);j+) if(stristrj) c=strj; |*found* strj=stri+; stri=c; void main() char str81; system(“CLS“): printf(“/nPlease enter a character string:“); gets(str); printf(“/n/nBefore sorting:

9、/n%S“,str); proc(str); printf(“/nAfter sorting decendingly:n%S“,str); (分数:30.00)解析:错误:int proc(char str) 正确:void proc(char str) 错误:strj=stri+; 正确:strj=stri; 解析 由主函数中的函数调用可知,函数 proc()没有返回值。因此,“int proc(char str)”应改为“void proc(char str)”;由函数 proc()可知,if 语句块完成将字符串str 中的第 i 个元素与第 j 个元素相交换。因此,“strj=stri+

10、应改为“strj=stri;”。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 proc(),它的功能是计算: s=(ln(1)+ln(2)+ln(3)+ln(m)0.5 在 C 语言中可调用 log(n)函数求 ln(n)。 例如,若 m 的值为 30,则 proc()函数值为 8.640500。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h #includemath.h dou

11、ble proc(int m) void main() system(“CLS“); printf(“%f/n“,proc(30); (分数:40.00)_正确答案:()解析:double proc(int m) int i; double s=0.0; /s 是表示其和 for(i=1;i=m;i+) s=s+log(i);/计算 s=ln(1)+ln(2)+ln(3)+ln(m) return sqrt(s); /最后将其开平方的值返回到主函数中 解析 由题目中所给表达式可知,表达式的值为 m 项表达式的和然后开平方。可以首先通过 m 次循环求得 m 项表达式的和,然后将其和开平方并返回到主函数当中。

展开阅读全文
相关资源
猜你喜欢
  • EN ISO 22088-4-2006 en Plastics - Determination of resistance to environmental stress cracking (ESC) - Part 4 Ball or pin impression method《塑料 耐环境应力碎裂的测定(ESC) 第4部分 球或钉压力法 ISO 22088.pdf EN ISO 22088-4-2006 en Plastics - Determination of resistance to environmental stress cracking (ESC) - Part 4 Ball or pin impression method《塑料 耐环境应力碎裂的测定(ESC) 第4部分 球或钉压力法 ISO 22088.pdf
  • EN ISO 22088-5-2009 en Plastics - Determination of resistance to environmental stress cracking (ESC) - Part 5 Constant tensile deformation method《塑料 耐环境应力开裂(ESC)能力的测定 第5部分 恒定拉伸变形法》.pdf EN ISO 22088-5-2009 en Plastics - Determination of resistance to environmental stress cracking (ESC) - Part 5 Constant tensile deformation method《塑料 耐环境应力开裂(ESC)能力的测定 第5部分 恒定拉伸变形法》.pdf
  • EN ISO 22088-6-2009 en Plastics - Determination of resistance to environmental stress cracking (ESC) - Part 6 Slow strain rate method《塑料 耐环境应力开裂(ESC)能力的测定 第6部分 慢应变速率法》.pdf EN ISO 22088-6-2009 en Plastics - Determination of resistance to environmental stress cracking (ESC) - Part 6 Slow strain rate method《塑料 耐环境应力开裂(ESC)能力的测定 第6部分 慢应变速率法》.pdf
  • EN ISO 22112-2006 en Dentistry - Artificial teeth for dental prostheses《牙科学 牙修复术用假牙(ISO 22112-2005)》.pdf EN ISO 22112-2006 en Dentistry - Artificial teeth for dental prostheses《牙科学 牙修复术用假牙(ISO 22112-2005)》.pdf
  • EN ISO 22112-2017 en Dentistry - Artificial teeth for dental prostheses.pdf EN ISO 22112-2017 en Dentistry - Artificial teeth for dental prostheses.pdf
  • EN ISO 22118-2011 en Microbiology of food and animal feeding stuffs - Polymerase chain reaction (PCR) for the detection and quantification of food-borne pathogens - Performance cha.pdf EN ISO 22118-2011 en Microbiology of food and animal feeding stuffs - Polymerase chain reaction (PCR) for the detection and quantification of food-borne pathogens - Performance cha.pdf
  • EN ISO 22119-2011 en Microbiology of food and animal feeding stuffs - Real-time polymerase chain reaction (PCR) for the detection of food-borne pathogens - General requirements and.pdf EN ISO 22119-2011 en Microbiology of food and animal feeding stuffs - Real-time polymerase chain reaction (PCR) for the detection of food-borne pathogens - General requirements and.pdf
  • EN ISO 22155-2013 6875 Soil quality - Gas chromatographic determination of volatile aromatic and halogenated hydrocarbons and selected ethers - Static headspace method《土质 挥发性芳烃与卤代烃.pdf EN ISO 22155-2013 6875 Soil quality - Gas chromatographic determination of volatile aromatic and halogenated hydrocarbons and selected ethers - Static headspace method《土质 挥发性芳烃与卤代烃.pdf
  • EN ISO 22155-2016 en Soil quality - Gas chromatographic determination of volatile aromatic and halogenated hydrocarbons and selected ethers - Static headspace method《土壤质量的气相色谱测定挥发性.pdf EN ISO 22155-2016 en Soil quality - Gas chromatographic determination of volatile aromatic and halogenated hydrocarbons and selected ethers - Static headspace method《土壤质量的气相色谱测定挥发性.pdf
  • 相关搜索

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

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