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

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

1、二级 C 语言机试-253 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)请补充函数 proc(),该函数的功能是:删除字符数组中小于指定字符的字符,指定字符从键盘输入,结果仍保存在原数组中。例如,输入“abcdefghij”,指定字符为“f”,则结果输出“fghij”。注意:部分源程序已给出。请勿改动主函数 main 和其他甬数中的任何内容。试题程序:#includestdlib.h#includestdio.h#define M 80void proc(char str, char ch)int i=0, j=0;while(stri)if

2、strich)(1) ;else(2) ;i+;(3) ;void main()char strN, ch;system(“CLS“);printf(“/n Input a string: /n“);gets(str);printf(“/n*original string*/n“);puts(str);printf(“n Input a charactor:/n“);scanf(“%c“, ch);proc(str, oh);printf(“/n*new string*/n“);puts(str);(分数:30.00)填空项 1:_填空项 1:_填空项 1:_二、改错题(总题数:1,分数:3

3、0.00)1.下列给定程序中,函数 proc()的功能是:从 m 个学生的成绩中统计出低于平均分的学生人数,人数由函数值返回,平均分存放在形参 aver 所指的存储单元中。例如输入 8 名学生的成绩:60 70 80 90 65 75 85 95则低于平均分的学生人数为 4(平均分为 77.5)。实际输入时学生数以回车键作为结束,成绩与成绩之间也与回车键作为分隔。请修改程序中的错误,使它能得到正确结果。注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。试题程序:#ineludestdlib.h#includestdio.h#includeconio.h#define M

4、20int proc (float *s, int n, float * aver)/*found*int ave, t=0;int count=0, k, i;for(k=0; kn; k+)t+=sk;ave=t/n;for(i=0; in; i+)/*found*if(siave)count+;/*found*aver=ave;return count;void main()float stu30, aver;int m, i;system(“CLS“);printf(“/nPlease enter m: “);scanf(“%d“, m);printf(“/nPlease enter%

5、d mark: /n“, m);for(i=0; im; i+)scanf(“%f“, stu+i);printf(“/nThe number of students: %d/n“,proc(stu, m, aver);printf(“Ave=%f/n“, aver);(分数:30.00)填空项 1:_三、编程题(总题数:1,分数:40.00)2.请编一个函数 float proc(double h),函数的功能是对变量 h 中的值保留两位小数,并对第 3 位进行四舍五入(规定 h 中的值为正数)。例如,若 h 值为 7.32596,则函数返回 7.33;若 h 值为 7.32496,则函数返

6、回 7.32。注意:部分源程序已给出。请勿改动主函数 main 和其他函数中的任何内容,仅在函数 proc 的花括号中填入所编写的若干语句。试题程序:#includestdlib.h#includestdio.h#includeconio.hfloat proc(float h)void main()float f;system(“CLS“);printf(“Enter f: “);scanf(“%f“, f);printf(“The original data is: “);printf(“%f/n/n“, f);printf(“The result: %f/n“, proc(f);(分数:

7、40.00)_二级 C 语言机试-253 答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)请补充函数 proc(),该函数的功能是:删除字符数组中小于指定字符的字符,指定字符从键盘输入,结果仍保存在原数组中。例如,输入“abcdefghij”,指定字符为“f”,则结果输出“fghij”。注意:部分源程序已给出。请勿改动主函数 main 和其他甬数中的任何内容。试题程序:#includestdlib.h#includestdio.h#define M 80void proc(char str, char ch)int i=0, j=0;while(s

8、tri)if(strich)(1) ;else(2) ;i+;(3) ;void main()char strN, ch;system(“CLS“);printf(“/n Input a string: /n“);gets(str);printf(“/n*original string*/n“);puts(str);printf(“n Input a charactor:/n“);scanf(“%c“, ch);proc(str, oh);printf(“/n*new string*/n“);puts(str);(分数:30.00)填空项 1:_ (正确答案:i+)解析:填空项 1:_ (正确

9、答案:strj+=stri)解析:填空项 1:_ (正确答案:strj=/0)解析:解析 要删除字符串中小于指定字符的字符,就要把字符串中每一个字符跟指定字符相比较,小于指定字符的字符不予处理。因此1处填 i+;把大于等于指定字符的字符保存在原字符串中,因此2处填 strj+=stri;处理完整个字符串后,为新生成的字符串添加结束符,因此3处填 strj=/0。二、改错题(总题数:1,分数:30.00)1.下列给定程序中,函数 proc()的功能是:从 m 个学生的成绩中统计出低于平均分的学生人数,人数由函数值返回,平均分存放在形参 aver 所指的存储单元中。例如输入 8 名学生的成绩:60

10、 70 80 90 65 75 85 95则低于平均分的学生人数为 4(平均分为 77.5)。实际输入时学生数以回车键作为结束,成绩与成绩之间也与回车键作为分隔。请修改程序中的错误,使它能得到正确结果。注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。试题程序:#ineludestdlib.h#includestdio.h#includeconio.h#define M 20int proc (float *s, int n, float * aver)/*found*int ave, t=0;int count=0, k, i;for(k=0; kn; k+)t+=sk

11、ave=t/n;for(i=0; in; i+)/*found*if(siave)count+;/*found*aver=ave;return count;void main()float stu30, aver;int m, i;system(“CLS“);printf(“/nPlease enter m: “);scanf(“%d“, m);printf(“/nPlease enter%d mark: /n“, m);for(i=0; im; i+)scanf(“%f“, stu+i);printf(“/nThe number of students: %d/n“,proc(stu, m

12、 aver);printf(“Ave=%f/n“, aver);(分数:30.00)填空项 1:_ (正确答案:(1)错误:int ave, t=0; 正确:float ave, t=0.0;(2)错误:if(siave) 正确:if(siave)(3)错误:aver=ave; 正确:*aver=ave;)解析:解析 由程序可知变量 ave 和 t 中分别存放的是学生的平均分数和分数的总和,都是 float 型数据。因此 int ave, t=0;应改为 float ave, t=0.0;题目要求统计出低于平均分数的学生人数,因此if(siave)应改为 if(siave);平均分数是通过指

13、针变量传递回主函数的,因此 aver=ave;改为*aver=ave。三、编程题(总题数:1,分数:40.00)2.请编一个函数 float proc(double h),函数的功能是对变量 h 中的值保留两位小数,并对第 3 位进行四舍五入(规定 h 中的值为正数)。例如,若 h 值为 7.32596,则函数返回 7.33;若 h 值为 7.32496,则函数返回 7.32。注意:部分源程序已给出。请勿改动主函数 main 和其他函数中的任何内容,仅在函数 proc 的花括号中填入所编写的若干语句。试题程序:#includestdlib.h#includestdio.h#includecon

14、io.hfloat proc(float h)void main()float f;system(“CLS“);printf(“Enter f: “);scanf(“%f“, f);printf(“The original data is: “);printf(“%f/n/n“, f);printf(“The result: %f/n“, proc(f);(分数:40.00)_正确答案:(float proc(float h)long t; t=(h*1000+5)/10;h*1000+5) /表示第三位进行四舍五入return(float)t/100; /h 中的值保留两位小数)解析:解析 要实现对变量的值保留两位小数,并对第三位小数进行四舍五入,可以通过先将其小数点后三位变为正数后加 5。所得到的数再除 10,最后再除 100 来实现。

展开阅读全文
相关资源
猜你喜欢
  • ASD-STAN PREN 3665-1995 Aerospace Series Test Methods for Paints and Varnishes Filiform Corrosion Resistance Test on Aluminium Alloys (Edition 1)《航空航天系列 油漆和清漆的试验方法 在铝合金上的耐丝状腐蚀试验 第1.pdf ASD-STAN PREN 3665-1995 Aerospace Series Test Methods for Paints and Varnishes Filiform Corrosion Resistance Test on Aluminium Alloys (Edition 1)《航空航天系列 油漆和清漆的试验方法 在铝合金上的耐丝状腐蚀试验 第1.pdf
  • ASD-STAN PREN 3666-1995 Aerospace Series Heat Resisting Alloy NI-PH2601 Solution Treated and Cold Worked Bar for Forged Fasteners D Less Than or Equal to 50 mm 1550 MPa Less Than o.pdf ASD-STAN PREN 3666-1995 Aerospace Series Heat Resisting Alloy NI-PH2601 Solution Treated and Cold Worked Bar for Forged Fasteners D Less Than or Equal to 50 mm 1550 MPa Less Than o.pdf
  • ASD-STAN PREN 3668-1997 Aerospace Series Heat Resisting Alloy NI-PH2301 (NiCr21Fe18Mo9) Non Heat Treated Forging Stock a or D Less Than or Equal to 250 mm (Edition P 1)《航空航天系列 a或D≤.pdf ASD-STAN PREN 3668-1997 Aerospace Series Heat Resisting Alloy NI-PH2301 (NiCr21Fe18Mo9) Non Heat Treated Forging Stock a or D Less Than or Equal to 250 mm (Edition P 1)《航空航天系列 a或D≤.pdf
  • ASD-STAN PREN 3671-1997 Aerospace Series Heat Resisting Alloy NI-PH3601 (NiCr22Mo9Nb) Non Heat Treated Forging Stock a or D Less Than or Equal to 250 mm (Edition P 1)《航空航天系列 a或D≤25.pdf ASD-STAN PREN 3671-1997 Aerospace Series Heat Resisting Alloy NI-PH3601 (NiCr22Mo9Nb) Non Heat Treated Forging Stock a or D Less Than or Equal to 250 mm (Edition P 1)《航空航天系列 a或D≤25.pdf
  • ASD-STAN PREN 3672-2015 Aerospace series Shank nuts self-locking in heat resisting nickel base alloy NI-P101HT (Waspaloy) silver plated for 30 wage Classification 1 210 MPa (at amb.pdf ASD-STAN PREN 3672-2015 Aerospace series Shank nuts self-locking in heat resisting nickel base alloy NI-P101HT (Waspaloy) silver plated for 30 wage Classification 1 210 MPa (at amb.pdf
  • ASD-STAN PREN 3675-1992 Aerospace Series Sampling Plan for Acceptance Testing of Aramid Carbon Fibre and Textile Glass Filament Yarns (Edition P 1)《航空航天系列 芳族聚酰胺纤维、碳纤维和纺织玻璃纤维长丝纱的验收试.pdf ASD-STAN PREN 3675-1992 Aerospace Series Sampling Plan for Acceptance Testing of Aramid Carbon Fibre and Textile Glass Filament Yarns (Edition P 1)《航空航天系列 芳族聚酰胺纤维、碳纤维和纺织玻璃纤维长丝纱的验收试.pdf
  • ASD-STAN PREN 3676-1993 Aerospace Series Inserts Thin Wall Design Standard (Edition P 1)《航空航天系列 薄壁嵌件 设计标准 第P1版》.pdf ASD-STAN PREN 3676-1993 Aerospace Series Inserts Thin Wall Design Standard (Edition P 1)《航空航天系列 薄壁嵌件 设计标准 第P1版》.pdf
  • ASD-STAN PREN 3677-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4) Air Melted Solution Treated and Precipitation Treated Forgings a or D Less Than or Equal to 200 mm Rm Greate.pdf ASD-STAN PREN 3677-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4) Air Melted Solution Treated and Precipitation Treated Forgings a or D Less Than or Equal to 200 mm Rm Greate.pdf
  • ASD-STAN PREN 3678-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4) Air Melted Solution Treated and Precipitation Treated Forgings a or D Less Than or Equal to 200 mm Rm Greate.pdf ASD-STAN PREN 3678-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4) Air Melted Solution Treated and Precipitation Treated Forgings a or D Less Than or Equal to 200 mm Rm Greate.pdf
  • 相关搜索

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

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