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

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

1、二级 C 语言-354 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:把 1100 的所有素数保存在数组 arr 中,然后输出这些素数并计算它们的和。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h void main() int i,j,k,flag,sum; int arr50; sum=0; k=0; system(

2、CLS“); for(i=2;i100;i+) 1; for(j=2;jij+) if(i%j=0) 2; if(flag) sum+=i; 3; printf(“/n*prime nHmber*/n“); for(i=0;ik;i+) if(i%10=0) printf(“/n“); printf(“%4d“,arri); printf(“/nsum=%d“,sum); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,proc()函数的功能是:根据形参 m,计算下列公式的值。 t=1+1/2+1/3+1/4+1/m 例如,若输入 10,则应输出 2.9

3、28968。请修改程序中的错误,使它能计算出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h double proc(int m) double t=1.0; int i; for(i=2;i=m;i+) /*found* t+=1.0/k; /*found* return i; void main() int m; system(“CLS“); printf(“/nPlease enter integer number:“); scanf(“%d

4、 printf(“/nThe result is%1f/n“,proc(m); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写函数 proc(),该函数的功能是:计算 n 门课程的平均分,计算结果作为函数值返回。 例如,有 6 门课程的成绩是 90.5,72,80,61.5,55,60,则函数的值为 69.83。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h float proc(float*a,int n) void main(

5、) float score30=90.5,72,80,61.5,55,60, aver; aver=proc(score,6); printf(“/nAverage score is:%5.2f/n“,aver); (分数:40.00)_二级 C 语言-354 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:把 1100 的所有素数保存在数组 arr 中,然后输出这些素数并计算它们的和。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线

6、上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h void main() int i,j,k,flag,sum; int arr50; sum=0; k=0; system(“CLS“); for(i=2;i100;i+) 1; for(j=2;jij+) if(i%j=0) 2; if(flag) sum+=i; 3; printf(“/n*prime nHmber*/n“); for(i=0;ik;i+) if(i%10=0) printf(“/n“); printf(“%4d“,arri); printf(“/nsum=%d“

7、sum); (分数:30.00)解析:flag=1 flag=0 arrk+=i解析 由整个程序可知,变量 flag 是判断一个整数是否为素数的标志,flag=1 为素数,flag=0 为非素数,此处将其初始值赋为 1,因此第一处填“flag=1”;当判断出一个整数为非素数时,将 flag 赋为 0,因此第二处填“flag=0”;题目要求将所有的素数放入数组 arr 中,因此第三处填“arrk+=i”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,proc()函数的功能是:根据形参 m,计算下列公式的值。 t=1+1/2+1/3+1/4+1/m 例如,若输入 10,则应输

8、出 2.928968。请修改程序中的错误,使它能计算出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h double proc(int m) double t=1.0; int i; for(i=2;i=m;i+) /*found* t+=1.0/k; /*found* return i; void main() int m; system(“CLS“); printf(“/nPlease enter integer number:“); scan

9、f(“%d“, printf(“/nThe result is%1f/n“,proc(m); (分数:30.00)解析:错误:t+=1.0/k; 正确:t+=1.0/i; 错误:return i; 正确:return t; 解析 根据 for 循环可知,变量 i 中存放每一项的分母,变量 k 在函数 proc 中没有定义,因此 t+=1.0/k;应改为 t+=1.0/i;。变量 t 中存放各项的和,题目要求将各项的和返回给主函数,因此 return i 应改为 return t。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 proc(),该函数的功能是:计算 n 门课程的平均分

10、计算结果作为函数值返回。 例如,有 6 门课程的成绩是 90.5,72,80,61.5,55,60,则函数的值为 69.83。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h float proc(float*a,int n) void main() float score30=90.5,72,80,61.5,55,60, aver; aver=proc(score,6); printf(“/nAverage score is:%5.2f/n“,aver); (分数:40.00)_正确答案:()解析:float proc(float*a,int n) float av=0.0; int i; for(i=0;in;i+) av=av+ai;/n 门课程的总分放到 av 中 return(av/n);/最后把其平均分作为函数值返回到主函数中 解析 要计算 n 门课程的平均分,首先可以求得 n 门课程的总分,然后除以 n 得到其平均分,最后将其平均分返回到主函数中。

展开阅读全文
相关资源
猜你喜欢
  • ASD-STAN PREN 2278-2013 Aerospace series Steel X12CrNiMoV12-3 (1 4933) 900 MPa Less than or equal to Rm Less than or equal to 1 100 MPa Bars De Less than or equal to 150 mm (Editio.pdf ASD-STAN PREN 2278-2013 Aerospace series Steel X12CrNiMoV12-3 (1 4933) 900 MPa Less than or equal to Rm Less than or equal to 1 100 MPa Bars De Less than or equal to 150 mm (Editio.pdf
  • ASD-STAN PREN 2279-1979 Steel FE-PM37 900 MPa Less Than or Equal to Rm Less Than or Equal to 1100 MPa Forgings De Less Than or Equal to 150 mm Aerospace Series (Edition 1)《航空航天系列 钢.pdf ASD-STAN PREN 2279-1979 Steel FE-PM37 900 MPa Less Than or Equal to Rm Less Than or Equal to 1100 MPa Forgings De Less Than or Equal to 150 mm Aerospace Series (Edition 1)《航空航天系列 钢.pdf
  • ASD-STAN PREN 2280-1979 Steel FE-PM37 900 MPa Less Than or Equal to Rm Less Than or Equal to 1100 MPa Sheet a Less Than or Equal to 6 mm Aerospace Series (Edition 1)《航空航天系列 钢FE-PM3.pdf ASD-STAN PREN 2280-1979 Steel FE-PM37 900 MPa Less Than or Equal to Rm Less Than or Equal to 1100 MPa Sheet a Less Than or Equal to 6 mm Aerospace Series (Edition 1)《航空航天系列 钢FE-PM3.pdf
  • ASD-STAN PREN 2281-1979 Steel FE-PM42 900 MPa Less Than or Equal to Rm Less Than or Equal to 1100 MPa Forgings De Less Than or Equal to 100 mm Aerospace Series (Edition 1)《航空航天系列 D.pdf ASD-STAN PREN 2281-1979 Steel FE-PM42 900 MPa Less Than or Equal to Rm Less Than or Equal to 1100 MPa Forgings De Less Than or Equal to 100 mm Aerospace Series (Edition 1)《航空航天系列 D.pdf
  • ASD-STAN PREN 2282-2002 Aerospace Series Characteristics of Aircraft Electrical Supplies (Edition P 1)《航空航天系列 航空器电源的特性 第P1版》.pdf ASD-STAN PREN 2282-2002 Aerospace Series Characteristics of Aircraft Electrical Supplies (Edition P 1)《航空航天系列 航空器电源的特性 第P1版》.pdf
  • ASD-STAN PREN 2283-2009 Aerospace series Testing of aircraft wiring (Edition P 1)《航空航天系列 航空器布线系统的试验 第P1版》.pdf ASD-STAN PREN 2283-2009 Aerospace series Testing of aircraft wiring (Edition P 1)《航空航天系列 航空器布线系统的试验 第P1版》.pdf
  • ASD-STAN PREN 2285-2002 Aerospace Series Bushes Plain Aluminium Alloy with Self-Lubricating Liner Dimensions and Loads (Edition P 1)《航空航天系列 带自润滑衬套的普通铝合金套管 尺寸和负荷 第P1版》.pdf ASD-STAN PREN 2285-2002 Aerospace Series Bushes Plain Aluminium Alloy with Self-Lubricating Liner Dimensions and Loads (Edition P 1)《航空航天系列 带自润滑衬套的普通铝合金套管 尺寸和负荷 第P1版》.pdf
  • ASD-STAN PREN 2286-2002 Aerospace Series Bushes Flanged Aluminium Alloy with Self-Lubricating Liner Dimensions and Loads (Edition P 1)《航空航天系列 带自润滑衬套的普通铝合金带凸缘套管 尺寸和负荷 第P1版》.pdf ASD-STAN PREN 2286-2002 Aerospace Series Bushes Flanged Aluminium Alloy with Self-Lubricating Liner Dimensions and Loads (Edition P 1)《航空航天系列 带自润滑衬套的普通铝合金带凸缘套管 尺寸和负荷 第P1版》.pdf
  • ASD-STAN PREN 2287-2002 Aerospace Series Bushes Plain Corrosion Resisting Steel with Self-Lubricating Liner Dimensions and Loads (Edition P 1)《航空航天系列 带自润滑衬套的普通耐蚀钢制套管 尺寸和负荷 第P1版》.pdf ASD-STAN PREN 2287-2002 Aerospace Series Bushes Plain Corrosion Resisting Steel with Self-Lubricating Liner Dimensions and Loads (Edition P 1)《航空航天系列 带自润滑衬套的普通耐蚀钢制套管 尺寸和负荷 第P1版》.pdf
  • 相关搜索

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

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