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

上传人:twoload295 文档编号:1325831 上传时间:2019-10-17 格式:DOC 页数:2 大小:31.50KB
下载 相关 举报
【计算机类职业资格】二级C语言机试33及答案解析.doc_第1页
第1页 / 共2页
【计算机类职业资格】二级C语言机试33及答案解析.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 C 语言机试 33 及答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充 main 函数,该函数的功能是:从键盘输入一个字符串并保存在字符 str1 中,把字符串 str1 中下标为偶数的字符保存在字符串 str2 中并输出。例如,当 str1=“cdefghij”,则 str2=“cegi”。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #includeconio.h #define LEN

2、 80 main() char str1LEN,str2 LEN; char *p1=str1,*p2=str2; int i=0,j=0; clrscr(); printf(“Enter the string:/n“); scanf(U 【1】 /U); printf(“*the origial string*/n“); while(*(p1+j) printf(“U 【2】 /U“,*(p1+j); j+; for(i=0;ij;i+=2) *p2+=*(str1+i); *p2=/0; printf(“/nThe new string is:%s/n“,U 【3】 /U); (分数:30

3、00)填空项 1:_二、B改错题/B(总题数:1,分数:30.00)2.在主函数中从键盘输入若干个数放入数组中,用 0 结束输入并放在最后一个元素中。下列给定程序中,函数 fun()的功能是计算数组元素中值为负数的平均值(不包括 0)。 例如:数组中元素的值依次为43,47,-21,53,-8,12, 0,则程序的运行结果为-25.333333。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include conio.h #include stdio.h double fun(int x) double su

4、m=0.0; int c=0,i=0; /*found*/ while(xi0) if(xi0) sum=sum+xi; c+; i+; /*found*/ sum=sum/c; return sum; main() int x1000; int i=0; clrscr(); printf(“/nPlease enter some data(end with 0) :”); do scanf(“%d“, 正确:sum=sum/c; 解析错误 1:此处考查的是对循环条件的理解,当被判断的数组元素为 0 时,说明这是数组的最后一个元素,此时要跳出循环。错误 2:C 语言中的除法运算符是“/”,而不

5、是“/”。三、B编程题/B(总题数:1,分数:40.00)3.请编写一个函数 int fun (int *s,int t,int *k),用来求出数组的最小元素在数组中的下标并存放在 k 所指的存储单元中。 例如,输入如下整数: 234 345 753 134 436 458 100 321 135 760 则输出结果为 6,100。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。 试题程序: #includeconio.h #includestdio.h int fun(int *s,int t,int *k) main() int a10=234,345,753,134,436,458, 100,321, 135,760),k; clrscr(); fun(a,10, *k=0 /*k 所指的数是数组的下标值*/ for(i=0;it;i+) if(s*ksi) *k=i; /*找到数组的最小元素,把该元素的下标赋给 k 所指的数*/ return s*k; /*返回数组的最小元素*/ 解析本题中直接使用指针变量 k,但在使用时要注意对 k的指针运算,此外,一开始应让*k 的值为数组中的某一下标值勤,即*k=0。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN ISO 15212-2-2002 Oscillation-type density meters - Part 2 Process instruments for homogeneous liquids (ISO 15212-2 2002) German version EN ISO 15212-2 2002《摆动式密度计 第2部分 同质液体测.pdf DIN EN ISO 15212-2-2002 Oscillation-type density meters - Part 2 Process instruments for homogeneous liquids (ISO 15212-2 2002) German version EN ISO 15212-2 2002《摆动式密度计 第2部分 同质液体测.pdf
  • DIN EN ISO 15216-1-2017 Microbiology of the food chain - Horizontal method for determination of hepatitis A virus and norovirus using real-time RT-PCR - Part 1 Method for quantific.pdf DIN EN ISO 15216-1-2017 Microbiology of the food chain - Horizontal method for determination of hepatitis A virus and norovirus using real-time RT-PCR - Part 1 Method for quantific.pdf
  • DIN EN ISO 1522-2007 Paints and varnishes - Pendulum damping test (ISO 1522 2006) English version of DIN EN ISO 1522 2007-04《色漆和清漆 摆阻尼试验》.pdf DIN EN ISO 1522-2007 Paints and varnishes - Pendulum damping test (ISO 1522 2006) English version of DIN EN ISO 1522 2007-04《色漆和清漆 摆阻尼试验》.pdf
  • DIN EN ISO 15223-1-2012 3154 Medical devices - Symbols to be used with medical device labels labelling and information to be supplied - Part 1 General requirements (Remains Current.pdf DIN EN ISO 15223-1-2012 3154 Medical devices - Symbols to be used with medical device labels labelling and information to be supplied - Part 1 General requirements (Remains Current.pdf
  • DIN EN ISO 15223-1-2017 Medical devices - Symbols to be used with medical device labels labelling and information to be supplied - Part 1 General requirements (ISO 15223-1 2016 Cor.pdf DIN EN ISO 15223-1-2017 Medical devices - Symbols to be used with medical device labels labelling and information to be supplied - Part 1 General requirements (ISO 15223-1 2016 Cor.pdf
  • DIN EN ISO 15225-2016 Medical devices - Quality management - Medical device nomenclature data structure (ISO 15225 2016) German version EN ISO 15225 2016《医疗设备 质量管理 医疗设备命名法数据结构(ISO .pdf DIN EN ISO 15225-2016 Medical devices - Quality management - Medical device nomenclature data structure (ISO 15225 2016) German version EN ISO 15225 2016《医疗设备 质量管理 医疗设备命名法数据结构(ISO .pdf
  • DIN EN ISO 1523 Berichtigung 1-2006 Determination of flash point - Closed cup equilibrium method (ISO 1523 2002) German version EN ISO 1523 2002 Corrigenda to DIN EN ISO 1523 2002-.pdf DIN EN ISO 1523 Berichtigung 1-2006 Determination of flash point - Closed cup equilibrium method (ISO 1523 2002) German version EN ISO 1523 2002 Corrigenda to DIN EN ISO 1523 2002-.pdf
  • DIN EN ISO 1523-2002 Determination of flash point - Closed cup equilibrium method (ISO 1523 2002) German version EN ISO 1523 2002《闪点测定 闭合杯平衡法 (ISO 1523 2002) 德文版本 EN ISO 1523 2002》.pdf DIN EN ISO 1523-2002 Determination of flash point - Closed cup equilibrium method (ISO 1523 2002) German version EN ISO 1523 2002《闪点测定 闭合杯平衡法 (ISO 1523 2002) 德文版本 EN ISO 1523 2002》.pdf
  • DIN EN ISO 15234-2011 Paints and varnishes - Testing of formaldehyde-emitting coatings and melamine foams - Determination of the steady-state concentration of formaldehyde in a sma.pdf DIN EN ISO 15234-2011 Paints and varnishes - Testing of formaldehyde-emitting coatings and melamine foams - Determination of the steady-state concentration of formaldehyde in a sma.pdf
  • 相关搜索

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

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