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

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

1、二级 C语言机试-146 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:33.00)1.请补充函数 fun(),该函数的功能是求一维数组 xN的平均值,并对所得结果进行四舍五入(保留两位小数)。例如:当 x10=15.6,19.9,16.7,15.2,18.3,12.1,15.5,11.0,10.0,16.0,结果为:avg=15.030000。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仪在函数 fun的横线上填入所编写的若干表达式或语句。试题程序:#includestdioh#includeconiohdouble fun

2、double x10)int i;long t;double avg=0.0;double sum=0.0;for(i=0;il0;i+)【1】 ;avg=sum/10;avg= 【2】 ;t= 【3】 ;avg=(double)t/100;return avg;main()double avg,x10=15.6,19.9,16.7,15.2,18.3,12.1,15.5,11.0,10.0,16.0;int i;clrscr();printf(“/nThe original data is:/n“);for(i=0;il0;i+)printf(“%6.lf“,xi);printf(“/n/

3、n“);avg=fun(x);printf(“average=%f/n/n“,avg);(分数:33.00)填空项 1:_二、改错题(总题数:1,分数:33.00)2.下列给定程序中,函数 fun()的功能是:先从键盘上输入一个 3行 3列的矩阵的各个元素的值,然后输出主对角线元素之积。请改正函数 fun()中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。试题程序: #includestdiohint fun()int a33,mu1;int i,j;mu1=l;for (i0;i3;i+)/*found*/for(i=0;i3;j+)sca

4、nf(“%d”,j3;j+) 正确:for(j=0;j3;j+)(2) 错误:mu1=mu1*aij; 正确:mu1=mul*aii;)解析:解析 错误 1:循环结构中,要给变量 j赋初值 0。错误 2:主对角元素的行号和列号相等,所以参加乘法的是 aii,而不是 aij。三、编程题(总题数:1,分数:34.00)3.学生的记录由学号和成绩组成,N 名学生的数据己在主函数中放入结构体数组 s中,请编写函数 fun(),它的功能是:把分数最低的学生数据放在 h所指的数组中。注意:分数低的学生可能不只一个,函数返回分数最低学生的人数。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的

5、任何内容,仅在函数 fun的花括号中填入所编写的若干语句。试题程序: #include stdioh#define N 16typedef structchar num10; int s;STREC;int fun (STREC *a,STREC *b)main ()STREC sN=“GA005“,82,“GA003“,75,“GA002“,85,“GA004“,78,“GA001“,95, “GA007“,62,“GA008“,60,“GA006“,85,“GA015“,83,“GA013“,94,“GA012“,78,“GA014“,97,“GA011“,60,“GA017“,65,“G

6、A018“,60,“GA016“,74;STREC hN;int i,n;FILE *out;n=fun(s,h); printf(“The %d lowest score:/n“,n);for (i=0;in;i+)printf(“%s %4d/n“,himum,his);/*输出最低分学生的学号和成绩*/printf(“/n“);out=fopen(“out19dat“,“w“);fprintf(out,“%d/n“,n);for(i=0;in;i+);fprintf(out,“%4d/n“,hi.s);fclose(out);(分数:34.00)_正确答案:(int fun (STREC *a,STREC *b)int i,j=0,min=a0s;for(i=0;iN;i+) if(minais)min=ai.s; /*找出最小值*/ for (i=0;iN;i+):if(min=ais)bj+=ai; /*找出成绩与 min相等的学生的记录,存入结构体 b中*/return j; /*返回最低成绩的学生人数*/)解析:解析 该程序使用循环嵌套,第 1个 for语句的作用是找出最小值。第 2个循环的作用是找出与min相等的成绩,也即最低成绩的学生记录,并存入 b中。

展开阅读全文
相关资源
猜你喜欢
  • ASTM E317-2016 red 6358 Standard Practice for Evaluating Performance Characteristics of Ultrasonic Pulse-Echo Testing Instruments and Systems without the Use of Electronic Measurem.pdf ASTM E317-2016 red 6358 Standard Practice for Evaluating Performance Characteristics of Ultrasonic Pulse-Echo Testing Instruments and Systems without the Use of Electronic Measurem.pdf
  • ASTM E319-1985(2003) Standard Practice for the Evaluation of Single-Pan Mechanical Balances《单盘机械天平的评定》.pdf ASTM E319-1985(2003) Standard Practice for the Evaluation of Single-Pan Mechanical Balances《单盘机械天平的评定》.pdf
  • ASTM E319-1985(2008) 952 Standard Practice for the Evaluation of Single-Pan Mechanical Balances《单盘机械天平的评定的标准实施规程》.pdf ASTM E319-1985(2008) 952 Standard Practice for the Evaluation of Single-Pan Mechanical Balances《单盘机械天平的评定的标准实施规程》.pdf
  • ASTM E319-1985(2014) 9251 Standard Practice for the Evaluation of Single-Pan Mechanical Balances《评估单盘机械天平的标准实践规程》.pdf ASTM E319-1985(2014) 9251 Standard Practice for the Evaluation of Single-Pan Mechanical Balances《评估单盘机械天平的标准实践规程》.pdf
  • ASTM E32-2015 7701 Standard Practices for Sampling Ferroalloys and Steel Additives for Determination of Chemical Composition《为测定铁合金和钢添加剂化学成分而进行取样的标准实施规程》.pdf ASTM E32-2015 7701 Standard Practices for Sampling Ferroalloys and Steel Additives for Determination of Chemical Composition《为测定铁合金和钢添加剂化学成分而进行取样的标准实施规程》.pdf
  • ASTM E321-1996(2005) Standard Test Method for Atom Percent Fission in Uranium and Plutonium Fuel (Neodymium-148 Method)《钕-148法测定铀和钚燃料中原子裂变百分比的标准试验方法》.pdf ASTM E321-1996(2005) Standard Test Method for Atom Percent Fission in Uranium and Plutonium Fuel (Neodymium-148 Method)《钕-148法测定铀和钚燃料中原子裂变百分比的标准试验方法》.pdf
  • ASTM E321-1996(2012) 6875 Standard Test Method for Atom Percent Fission in Uranium and Plutonium Fuel (Neodymium-148 Method) 《铀和钚燃料中原子裂变百分比的标准试验方法(钕-148法)》.pdf ASTM E321-1996(2012) 6875 Standard Test Method for Atom Percent Fission in Uranium and Plutonium Fuel (Neodymium-148 Method) 《铀和钚燃料中原子裂变百分比的标准试验方法(钕-148法)》.pdf
  • ASTM E322-1996(2004) Standard Test Method for X-Ray Emission Spectrometric Analysis of Low-Alloy Steels and Cast Irons《低合金钢和铸铁的X射线发射光谱测定分析法》.pdf ASTM E322-1996(2004) Standard Test Method for X-Ray Emission Spectrometric Analysis of Low-Alloy Steels and Cast Irons《低合金钢和铸铁的X射线发射光谱测定分析法》.pdf
  • ASTM E322-2012 0804 Standard Test Method for Analysis of Low-Alloy Steels and Cast Irons by Wavelength Dispersive X-Ray Fluorescence Spectrometry 《用波长色散X射线荧光光谱法分析低合金钢和铸铁的标准试验方法》.pdf ASTM E322-2012 0804 Standard Test Method for Analysis of Low-Alloy Steels and Cast Irons by Wavelength Dispersive X-Ray Fluorescence Spectrometry 《用波长色散X射线荧光光谱法分析低合金钢和铸铁的标准试验方法》.pdf
  • 相关搜索

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

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