【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷417及答案解析.doc

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

1、国家二级 C语言机试(操作题)模拟试卷 417及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是: 计算形参 x所指数组中 N个数的平均值(规定所有数均为正数),将所指数组中小于平均值的数据移至数组的前部,大于等于平均值的数据移至 x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。 例如,有 10个正数:47、30、32、40、6、17、45、15、48、26,其平均值为 30 500000。 移动后的输出为:30、6、17、15、26、47、32、40、45、48。 请在程序的下画线处填

2、入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1C 中。 不得增行或删行,也不得更改程序的结构!试题程序: #include stdlibh #include stdioh #define N 10 double fun (double *x) int i, j; double av, y N; av =0; /*found*/ av+= 【1】 ; for(i=j=0;i N;i+) if(xi av) yj=xi;xi=一 1; /*found*/ 【2】 ; i=0; while (i N) if(xi!=一 1)yj+=xi; /*found*/

3、 【3】 ; for(i=0;i N;i+)xi=yi; return av; main () int i; double xN; printf (“/n“) ; printf (“/nThe average is: f/n“, printf (“/nThe result :/n“,fun (x) ; printf (“ 5Of “,xi) ; printf (“/n“); (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.下列给定函数中,函数 fun的功能是:统计字符串中各元音字母(即 A、E、I、O、U)的个数。注意:字母不分大小写。 例如,输入”THls is a bo

4、ot”,则应输出是 1 0 2 2 0。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODI1C 中,不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include stdlibh #include conioh #include stdioh /*found*/fun (char * s, int num 5 ) int k, i=5;for(k=0,k i;k+)/*found*/ numi =0;/*found*/ switch (s) casea: caseA: i = 0 ;break; case e: case E : 1 =1;

5、break; case i: case I: 1 =2;break; case o: case O: 1 =3;breakf case u: case U: 1 =4;break; i=4 ; break; if(i =0) numi+; void main()char s181;int numl5,i; system(“CLS“),printf(“/nPlease enter astring:“); gets(s1); fun(s1,num1); for(i=0;i 5;i+) printf(“d“,numli); printf(“/n“);(分数:2.00)_三、程序设计题(总题数:1,分

6、数:2.00)3.请编写函数 fun,该函数的功能是:求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如,若二维数组中的值为: 1 3 5 7 9 2 9 9 9 4 6 9 9 9 8 1 3 5 7 0 则函数值为61。 注意:部分源程序在文件 PROG1C 中。 请勿改主动函数 main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include conioh #include stdio h #include stdlibh #define M 4#define N 5int fun ( int a M N1) void

7、 main () FILE *wf; int aaM N = 1,3,5,7,9 ,2,9,9,9,4, 6,9,9,9,8,1,3,5,7,0 ; int i, j, y; system (“CLS “) ; printf (“The original data is for (1 =0; i Mf i+) printf (“ 6d “,aai j ) ; printf (“/n “) ; y = fun (aa) ; printf (“/nThe sun: d/n “y) ; printf (“/n “) ;/*found*/ wf = fopen (“outdat“, “w“) ; fp

8、rintf (wf, “ d“, y) ; fclose (wf) ;/*found*/(分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 417答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是: 计算形参 x所指数组中 N个数的平均值(规定所有数均为正数),将所指数组中小于平均值的数据移至数组的前部,大于等于平均值的数据移至 x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。 例如,有 10个正数:47、30、32、40、6、17、45、15、48、26,其平均值为 30 500

9、000。 移动后的输出为:30、6、17、15、26、47、32、40、45、48。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1C 中。 不得增行或删行,也不得更改程序的结构!试题程序: #include stdlibh #include stdioh #define N 10 double fun (double *x) int i, j; double av, y N; av =0; /*found*/ av+= 【1】 ; for(i=j=0;i N;i+) if(xi av) yj=xi;xi=一 1; /*found*

10、/ 【2】 ; i=0; while (i N) if(xi!=一 1)yj+=xi; /*found*/ 【3】 ; for(i=0;i N;i+)xi=yi; return av; main () int i; double xN; printf (“/n“) ; printf (“/nThe average is: f/n“, printf (“/nThe result :/n“,fun (x) ; printf (“ 5Of “,xi) ; printf (“/n“); (分数:2.00)_正确答案:(正确答案:(1)xi/N (2)j+或+j (3)i+或+i)解析:解析:填空 1:

11、av代表平均值,本题考查了怎样求平均值,因此本空应该填写 xi/N。 填空 2:通过 for循环和 if判断找到 xi中比平均值小的数,并把这些值赋值给 yj,因此本空应该填写 j+或者+j。 填空 3:通过 while循环语句,把 xi中比平均值大的数放在数组 y的后半部分,因此本空应该填写 i+或者+i。二、程序修改题(总题数:1,分数:2.00)2.下列给定函数中,函数 fun的功能是:统计字符串中各元音字母(即 A、E、I、O、U)的个数。注意:字母不分大小写。 例如,输入”THls is a boot”,则应输出是 1 0 2 2 0。 请改正程序中的错误,使它能得出正确的结果。 注

12、意:部分源程序在文件 MODI1C 中,不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include stdlibh #include conioh #include stdioh /*found*/fun (char * s, int num 5 ) int k, i=5;for(k=0,k i;k+)/*found*/ numi =0;/*found*/ switch (s) casea: caseA: i = 0 ;break; case e: case E : 1 =1;break; case i: case I: 1 =2;break; case o: c

13、ase O: 1 =3;breakf case u: case U: 1 =4;break; i=4 ; break; if(i =0) numi+; void main()char s181;int numl5,i; system(“CLS“),printf(“/nPlease enter astring:“); gets(s1); fun(s1,num1); for(i=0;i 5;i+) printf(“d“,numli); printf(“/n“);(分数:2.00)_正确答案:(正确答案:(1)void fun(char *s, int num5) (2)numk =0; (3)sw

14、itch(*s))解析:解析:switch 语句说明如下: (1)switch 后的表达式,可以是整型或字符型,也可以是枚举类型。在新的 ANSIC标准中允许表达式的类型为任何类型。 (2)每个 case后的常量表达式只能是由常量组成的表达式,当 switch后表达式的值与某一个常量表达式的值一致时,程序就转到此 case后的语句开始执行。如果没有一个常量表达式的值与 switch后的值一致,就执行 default后的语句。 (3)各个 case后的常量表达式的值必须互不相同。 (4)各个 case的次序不影响执行结果,一般情况下,尽量将出现概率大的case放在前面。 (5)在执行完一个 ca

15、se后面的语句后,程序会转到下一个 case后的语句开始执行,因而必须使用 break语句才能跳出。三、程序设计题(总题数:1,分数:2.00)3.请编写函数 fun,该函数的功能是:求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如,若二维数组中的值为: 1 3 5 7 9 2 9 9 9 4 6 9 9 9 8 1 3 5 7 0 则函数值为61。 注意:部分源程序在文件 PROG1C 中。 请勿改主动函数 main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include conioh #include stdio h

16、include stdlibh #define M 4#define N 5int fun ( int a M N1) void main () FILE *wf; int aaM N = 1,3,5,7,9 ,2,9,9,9,4, 6,9,9,9,8,1,3,5,7,0 ; int i, j, y; system (“CLS “) ; printf (“The original data is for (1 =0; i Mf i+) printf (“ 6d “,aai j ) ; printf (“/n “) ; y = fun (aa) ; printf (“/nThe sun: d/

17、n “y) ; printf (“/n “) ;/*found*/ wf = fopen (“outdat“, “w“) ; fprintf (wf, “ d“, y) ; fclose (wf) ;/*found*/(分数:2.00)_正确答案:(正确答案:int fun(int aM N) int i,j,sum =0; for(i=0;i M;i+) for(j=0;j N;j+) if(i=一 0 1 11 =M 一 1|j=0 |j=N一 1)/* 只要下标中有一个为 0或 M 一1或 N一 1,则它一定是周边元素*/ sum=sum+aij;/* 将周边元素相加*/ return sum; )解析:解析:本题采用逐一判断的方式。二维数组周边元素的规律是,其两个下标值中一定有一个是 0或 M 一 1或 N 一 1。程序中循环语句用来控制数组的行和列,条件语句用来判断数组元素是否为周边元素。

展开阅读全文
相关资源
猜你喜欢
  • BS EN 1515-3-2005 Flanges and their joints - Bolting - Classification of bolt materials for steel flanges class designated《法兰及其连接件 螺栓连接 等级标注的钢法兰用螺栓材料的分类》.pdf BS EN 1515-3-2005 Flanges and their joints - Bolting - Classification of bolt materials for steel flanges class designated《法兰及其连接件 螺栓连接 等级标注的钢法兰用螺栓材料的分类》.pdf
  • BS EN 1515-4-2009 Flanges and their joints - Bolting - Selection of bolting for equipment subject to the Pressure Equipment Directive 97 23 EC《法兰及其连接件 螺栓连接 压力设备指令97 23 EC控制的设备用螺栓连接.pdf BS EN 1515-4-2009 Flanges and their joints - Bolting - Selection of bolting for equipment subject to the Pressure Equipment Directive 97 23 EC《法兰及其连接件 螺栓连接 压力设备指令97 23 EC控制的设备用螺栓连接.pdf
  • BS EN 1516-1999 Surfaces for sports areas - Determination of resistance to indentation《体育场场区的表面 耐压痕能力的测定》.pdf BS EN 1516-1999 Surfaces for sports areas - Determination of resistance to indentation《体育场场区的表面 耐压痕能力的测定》.pdf
  • BS EN 1517-2000 Surfaces for sports areas - Determination of resistance to impact《体育场场区的表面 抗冲击性能的测定》.pdf BS EN 1517-2000 Surfaces for sports areas - Determination of resistance to impact《体育场场区的表面 抗冲击性能的测定》.pdf
  • BS EN 1518-1998 Non-destructive testing - Leak testing - Characterization of mass spectrometer leak detectors《无损检验 漏泄试验 质谱仪漏泄检测器特性》.pdf BS EN 1518-1998 Non-destructive testing - Leak testing - Characterization of mass spectrometer leak detectors《无损检验 漏泄试验 质谱仪漏泄检测器特性》.pdf
  • BS EN 1519-1-2000 Plastics piping systems for soil and waste discharge (low and high temperature) within the building structure Polyethylene (PE) Specifications for pipes fittings .pdf BS EN 1519-1-2000 Plastics piping systems for soil and waste discharge (low and high temperature) within the building structure Polyethylene (PE) Specifications for pipes fittings .pdf
  • BS EN 152-2011 Wood preservatives Determination of the protective effectiveness of a preservative treatment against blue stain in wood in service Laboratory method《木材防腐剂 使用中防蓝变防腐处理.pdf BS EN 152-2011 Wood preservatives Determination of the protective effectiveness of a preservative treatment against blue stain in wood in service Laboratory method《木材防腐剂 使用中防蓝变防腐处理.pdf
  • BS EN 1520-2011 Prefabricated reinforced components of lightweight aggregate concrete with open structure with structural or non-structural reinforcement《结构化和非结构化加固透空结构的轻型骨料混凝土预制增强.pdf BS EN 1520-2011 Prefabricated reinforced components of lightweight aggregate concrete with open structure with structural or non-structural reinforcement《结构化和非结构化加固透空结构的轻型骨料混凝土预制增强.pdf
  • BS EN 1521-1997 Determination of flexural strength of lightweight aggregate concrete with open structure《开式结构轻集料混凝土挠曲强度的测定》.pdf BS EN 1521-1997 Determination of flexural strength of lightweight aggregate concrete with open structure《开式结构轻集料混凝土挠曲强度的测定》.pdf
  • 相关搜索

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

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