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

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

1、二级 C 语言-276 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:计算下式前 n 项的和作为函数值返回。 (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.给定程序中函数 fun 的功能是:判断一个整数是否是素数,若是返回 1,否则返回 0。在 main()函数中,若 fun 返回 1 输出 YES,若 fun 返回 0 输出 NO!。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数。不得增行或删行,也不得更改程序的结构! 给定源程序: #inclu

2、destdio.h int fun(int m) int k=2; while(k=m else return 0; main() int n; printf(“/nPlease enter n:“); scanf(“%d“, if(fun(n)printf(“YES/n“); else printf(“NO!/n“); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写一个函数 fun,它的功能是:找出一维整型数组元素中最大的值和它所在的下标,最大的值和它所在的下标通过形参传回。数组元素中的值已在主函数中赋予。 主函数中 x 是数组名,n 是 x 中的数据个数,ma

3、x 存放最大值,index 存放最大值所在元素的下标。 请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #includestdlib.h #includestdio.h void fun(int a, int n, int *max, int *d) main() int i, x20, max, index, n=10; for(i=0; in; i+)xi=rand()%50; printf(“%4d“, xi); printf(“/n“); fun(x, n, printf(“Max=%5d, Index=%4d/n“,

4、 max, index); (分数:40.00)_二级 C 语言-276 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:计算下式前 n 项的和作为函数值返回。 (分数:30.00)解析:(1)1 (2)2*i (3)(-1) 解析 填空 1:由 fun 函数整体结构可以看出 k 的作用是赋值,并累加各项前边的正负号,由于第一项是正的,因此赋给 k 的值为 1。 填空 2:此空下一行的表达式 k*(2*i-1)*(2*i+1)/(t*t)累加的通向,k 为正负号,由题目中公式可知t=2*i。 填空 3:由

5、于通向前边的正负号每次都要发生变化,因此 k=k*(-1)。二、程序改错题(总题数:1,分数:30.00)2.给定程序中函数 fun 的功能是:判断一个整数是否是素数,若是返回 1,否则返回 0。在 main()函数中,若 fun 返回 1 输出 YES,若 fun 返回 0 输出 NO!。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数。不得增行或删行,也不得更改程序的结构! 给定源程序: #includestdio.h int fun(int m) int k=2; while(k=m else return 0; main() int n; printf(“/

6、nPlease enter n:“); scanf(“%d“, if(fun(n)printf(“YES/n“); else printf(“NO!/n“); (分数:30.00)解析:(1)k+; (2)if(m=k) 解析 函数 fun 的功能是判断 m 是否为素数:m 从 2 开始作为除数,并对 m 取余,若不存在一个数使得余数为 0,则 m 为素数,第一处程序错误丢失分号,第二处程序的错误在于 if(m=k)语句中的逻辑表达式写成了赋值语句。三、程序设计题(总题数:1,分数:40.00)3.请编写一个函数 fun,它的功能是:找出一维整型数组元素中最大的值和它所在的下标,最大的值和它所

7、在的下标通过形参传回。数组元素中的值已在主函数中赋予。 主函数中 x 是数组名,n 是 x 中的数据个数,max 存放最大值,index 存放最大值所在元素的下标。 请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #includestdlib.h #includestdio.h void fun(int a, int n, int *max, int *d) main() int i, x20, max, index, n=10; for(i=0; in; i+)xi=rand()%50; printf(“%4d“, xi);

8、 printf(“/n“); fun(x, n, printf(“Max=%5d, Index=%4d/n“, max, index); (分数:40.00)_正确答案:()解析:void fun(int a, int n, int *max, int *d) int i; *max=a0; *d=0; for(i=0; in; i+) if(*maxai) *max=ai; *d=i; 解析 要查找最大值及其下标需要定义两个变量,该程序直接使用形参 max 和 d,由于它们都是指针变量,所以在引用它所指向的变量时要对它进行指针运算。循环语句用来遍历数组元素,条件语句用来判断该数组元素是否最大。

展开阅读全文
相关资源
猜你喜欢
  • DIN 26053-2016 Trusted measurement technique for tank vehicles for the delivery of fuel oil EL diesel fuel and biodiesel to the end-consumer《对最终用户EL型燃油、柴油和生物柴油交付用槽罐车的可靠计量技术》.pdf DIN 26053-2016 Trusted measurement technique for tank vehicles for the delivery of fuel oil EL diesel fuel and biodiesel to the end-consumer《对最终用户EL型燃油、柴油和生物柴油交付用槽罐车的可靠计量技术》.pdf
  • DIN 26054-2008 Non-metallic corrugated hose assemblies for chemical products《化学产品用非金属螺纹软管组件》.pdf DIN 26054-2008 Non-metallic corrugated hose assemblies for chemical products《化学产品用非金属螺纹软管组件》.pdf
  • DIN 26055-2-2010 Hose assemblies for use in the pharmaceutical and biotechnological industry with hoses of non-metallic materials - Part 2 Silicone rubber hoses《制药和生物技术行业用带非金属材料软管的.pdf DIN 26055-2-2010 Hose assemblies for use in the pharmaceutical and biotechnological industry with hoses of non-metallic materials - Part 2 Silicone rubber hoses《制药和生物技术行业用带非金属材料软管的.pdf
  • DIN 26055-3-2010 Hose assemblies for use in the pharmaceutical and biotechnological industry with hoses of non-metallic materials - Part 3 Elastomeric hoses with or without liner《制.pdf DIN 26055-3-2010 Hose assemblies for use in the pharmaceutical and biotechnological industry with hoses of non-metallic materials - Part 3 Elastomeric hoses with or without liner《制.pdf
  • DIN 26057-2016 Spiralled hoses made of thermoplastic polyurethan (TPU) with steel wire reinforcement for granulated and powdered materials - Requirements《钢丝强化热塑性聚氨酯 (TPU) 制成的粒状和粉状材.pdf DIN 26057-2016 Spiralled hoses made of thermoplastic polyurethan (TPU) with steel wire reinforcement for granulated and powdered materials - Requirements《钢丝强化热塑性聚氨酯 (TPU) 制成的粒状和粉状材.pdf
  • DIN 2607-2002 Tube bends - For butt-welding of copper《管弯头 铜对接焊用》.pdf DIN 2607-2002 Tube bends - For butt-welding of copper《管弯头 铜对接焊用》.pdf
  • DIN 261-2010 T-head bolts《T形头螺栓》.pdf DIN 261-2010 T-head bolts《T形头螺栓》.pdf
  • DIN 262-1-1973 Round Screw Thread with Clearance and Steep Flank with Pitch 7 mm Nominal Dimensions《螺距为7mm 的带间隙和直侧面的圆螺纹 标称尺寸》.pdf DIN 262-1-1973 Round Screw Thread with Clearance and Steep Flank with Pitch 7 mm Nominal Dimensions《螺距为7mm 的带间隙和直侧面的圆螺纹 标称尺寸》.pdf
  • DIN 262-2-1973 Round Screw Thread with Clearance and Steep Flank with Pitch 7 mm Limiting Dimensions of Screw Threads and Allowances-Permissible Deviations and Permissible Wear of .pdf DIN 262-2-1973 Round Screw Thread with Clearance and Steep Flank with Pitch 7 mm Limiting Dimensions of Screw Threads and Allowances-Permissible Deviations and Permissible Wear of .pdf
  • 相关搜索

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

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