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

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

1、国家二级 C语言机试(操作题)模拟试卷 420及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是: 找出 NxN矩阵中每列元素中的最大值,并按顺序依次存放于形参 b所指的一维数组中。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1C 中。 不得增行或删行,也不得更改程序的结构! 试题程序: #include stdioh #define N 4 void fun (int (*a) N, int *b) int i,j; for(i=0;i N;i+)

2、/*found*/ bi= 【1】 ; for(j=1;j N;j+) /*found*/ if (bi 【2】 aji) bi=aji; main() int xNN=12,5,8,7, 6,1,9,3),1,2,3,4),2,8,4,3, yN,i; printf (“/nThe matrix :/n“) ; for(i=O;i N;i+) for(j=0;j N;j+) printf (f 4d“,xi jl) ; printf (“/n“) ; /*found*/ fun ( 【3】 ); printf (“/nThe result is:“) ; for(i=0;i N;i+) pr

3、intf (“3d“,yi) ; printf (“/n“) ; (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能 是:将主函数中两个变量的值进行交换。例如,若变量 a中的值为8,b 中的值为 3,则程序运行后,a 中的值为 3,b 中的值为 8。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODI1C 中,不要改动 maln函数,不得增行或删行,也不得更改程序的结构! 试题程序:#include stdioh /*found*/void fun (int x,int y) int t;/*found*/t=x;x

4、=y;y=t;void main () int a,b; a =8; b =3;fun(&a,&b); printf (“ d d/n “, a,b) ; (分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.编写函数 int fun( int lim,int aa MAX),其功能是求出小于或等于 lim的所有素数并放在 aa数组中,并返回所求出的素数的个数。 注意:部分源程序在文件 PROG1C 中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序:#include conioh #include stdio h #

5、include stdlib h #define MAX 100int fun (int lim, int aaMAX)void main () FILE *wf; int limit,i, sum; int aaMAX ; system (“CLS“) ; printf “输入_个整数: “ ) : scanf ( “ d“ , &limit) ; sum = fun (limit,aa) ; for (i =0;i sum;i+) if (1 10 =0&i!=0)/ *每行输出 10个数 * / printf (“/n “) ; printf (“ 5d “,aai ) : /*foun

6、d*/ wf = fopen (“outdat“, “w“) ; sum = fun (15, aa) ; for (i =0;i sum;i +) if (1 10 =0&11=0)/*每行输出 10 个数* / fprintf (wf, “/n“) ; fprintf (wf, “5d “,aai ) ; fclose (wf) ;/*found*/(分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 420答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是: 找出 NxN矩阵中每列元素中的最大值,并按顺序

7、依次存放于形参 b所指的一维数组中。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1C 中。 不得增行或删行,也不得更改程序的结构! 试题程序: #include stdioh #define N 4 void fun (int (*a) N, int *b) int i,j; for(i=0;i N;i+) /*found*/ bi= 【1】 ; for(j=1;j N;j+) /*found*/ if (bi 【2】 aji) bi=aji; main() int xNN=12,5,8,7, 6,1,9,3),1,2,3,4),

8、2,8,4,3, yN,i; printf (“/nThe matrix :/n“) ; for(i=O;i N;i+) for(j=0;j N;j+) printf (f 4d“,xi jl) ; printf (“/n“) ; /*found*/ fun ( 【3】 ); printf (“/nThe result is:“) ; for(i=0;i N;i+) printf (“3d“,yi) ; printf (“/n“) ; (分数:2.00)_正确答案:(正确答案:(1)a0i (2) (3)x,y)解析:解析:填空 1:数组 b用于存放每列元素中的最大值,首先将第 i列的第一个数

9、赋给 bi,然后用bi与其他数进行比较,因此此空应填 a0i。 填空 2:if 条件表达式表示当 bi小于 aji时,就把 aji的值赋给 bi,因此此空应该填 。 填空 3:fun 函数的调用,通过 fun(int(*a)N,int*b)可知,此空应该填 x,y。二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能 是:将主函数中两个变量的值进行交换。例如,若变量 a中的值为8,b 中的值为 3,则程序运行后,a 中的值为 3,b 中的值为 8。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODI1C 中,不要改动 maln函数,不得增

10、行或删行,也不得更改程序的结构! 试题程序:#include stdioh /*found*/void fun (int x,int y) int t;/*found*/t=x;x=y;y=t;void main () int a,b; a =8; b =3;fun(&a,&b); printf (“ d d/n “, a,b) ; (分数:2.00)_正确答案:(正确答案:(1) void fun(int*xint*y) (2)t=*x; *x=*y; *y =t;)解析:解析:(1)本题考查指针变量作函数参数。一般变量作参数时,不能改变实参的值,采用指针变量作为参数则能够改变实参的值。主函

11、数中 fun函数的调用方式表明 fun函数的参数应当为指针类型。 (2)此处是一个变量交换操作错误,可知 x、y 是指针类型,变量类型不同,因而 x、y 不能与 t进行值的交换。三、程序设计题(总题数:1,分数:2.00)3.编写函数 int fun( int lim,int aa MAX),其功能是求出小于或等于 lim的所有素数并放在 aa数组中,并返回所求出的素数的个数。 注意:部分源程序在文件 PROG1C 中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序:#include conioh #include stdio h

12、#include stdlib h #define MAX 100int fun (int lim, int aaMAX)void main () FILE *wf; int limit,i, sum; int aaMAX ; system (“CLS“) ; printf “输入_个整数: “ ) : scanf ( “ d“ , &limit) ; sum = fun (limit,aa) ; for (i =0;i sum;i+) if (1 10 =0&i!=0)/ *每行输出 10个数 * / printf (“/n “) ; printf (“ 5d “,aai ) : /*fou

13、nd*/ wf = fopen (“outdat“, “w“) ; sum = fun (15, aa) ; for (i =0;i sum;i +) if (1 10 =0&11=0)/*每行输出 10 个数* / fprintf (wf, “/n“) ; fprintf (wf, “5d “,aai ) ; fclose (wf) ;/*found*/(分数:2.00)_正确答案:(正确答案:int fun (int lim, int aa MAX) int i,j,k =0; for(i=2;i =1im;i+)/*求出小于或等于 lim的全部素数*/ for(j=2; j i; j+) if (ij =0) break; if(j =i) aak+=i;/*将求出的素数放入数组 aa中*/ return k;/*返回所求出的素数的个数*/ )解析:解析:本程序如果一个数是合数,那么它的最小质因数肯定小于等于他的平方根。使用 for循环语句查找小于 lim的所有数,使用内嵌的循环判断语句判断该数是否为素数。在做这道题时,需要重点掌握素数的判定方法: for(j =2;j sqrt(i);j+) if(ij=0) break;

展开阅读全文
相关资源
猜你喜欢
  • EN 16256-4-2012 en Pyrotechnic articles - Theatrical pyrotechnic articles - Part 4 Minimum labelling requirements and instructions for use《烟火用品 戏剧烟火用品 第4部分 最低标签要求和使用要求》.pdf EN 16256-4-2012 en Pyrotechnic articles - Theatrical pyrotechnic articles - Part 4 Minimum labelling requirements and instructions for use《烟火用品 戏剧烟火用品 第4部分 最低标签要求和使用要求》.pdf
  • EN 16256-5-2012 en Pyrotechnic articles - Theatrical pyrotechnic articles - Part 5 Test methods《烟火用品 戏剧烟火用品 第5部分 测试方法》.pdf EN 16256-5-2012 en Pyrotechnic articles - Theatrical pyrotechnic articles - Part 5 Test methods《烟火用品 戏剧烟火用品 第5部分 测试方法》.pdf
  • EN 16257-2012 en Tanks for the transport of dangerous goods - Service equipment - Footvalve sizes other than 100 mm dia (nom)《坦克对危险货物的运输服务设备 Footvalve尺寸100毫米dia以外》.pdf EN 16257-2012 en Tanks for the transport of dangerous goods - Service equipment - Footvalve sizes other than 100 mm dia (nom)《坦克对危险货物的运输服务设备 Footvalve尺寸100毫米dia以外》.pdf
  • EN 16258-2012 en Methodology for calculation and declaration of energy consumption and GHG emissions of transport services (freight and passengers)《运输服务的能源消耗和温室气体(GHG)排放的计算和申报方法(货运.pdf EN 16258-2012 en Methodology for calculation and declaration of energy consumption and GHG emissions of transport services (freight and passengers)《运输服务的能源消耗和温室气体(GHG)排放的计算和申报方法(货运.pdf
  • EN 16260-2011 en Water quality - Visual seabed surveys using remotely operated and towed observation gear for collection of environmental data《水的质量 使用远程操作和拖曳式观测设备收集环境数据的视觉海底调查》.pdf EN 16260-2011 en Water quality - Visual seabed surveys using remotely operated and towed observation gear for collection of environmental data《水的质量 使用远程操作和拖曳式观测设备收集环境数据的视觉海底调查》.pdf
  • EN 16260-2012 5625 Water quality - Visual seabed surveys using remotely operated and or towed observation gear for collection of environmental data《水质 环境数据的收集用遥感操作和 或拖曳监测齿轮进行可视化海底调.pdf EN 16260-2012 5625 Water quality - Visual seabed surveys using remotely operated and or towed observation gear for collection of environmental data《水质 环境数据的收集用遥感操作和 或拖曳监测齿轮进行可视化海底调.pdf
  • EN 16261-1-2012 en Pyrotechnic articles - Fireworks category 4 - Part 1 Terminology《烟火制品 4类烟火 第1部分 术语 德文版本EN 16261-1-2012》.pdf EN 16261-1-2012 en Pyrotechnic articles - Fireworks category 4 - Part 1 Terminology《烟火制品 4类烟火 第1部分 术语 德文版本EN 16261-1-2012》.pdf
  • EN 16261-2-2013 en Pyrotechnic articles - Fireworks Category 4 - Part 2 Requirements《烟火用品 烟花 类别4 第2部分 需求》.pdf EN 16261-2-2013 en Pyrotechnic articles - Fireworks Category 4 - Part 2 Requirements《烟火用品 烟花 类别4 第2部分 需求》.pdf
  • EN 16261-3-2012 en Pyrotechnic articles - Fireworks Category 4 - Part 3 Test methods《烟火用品 烟花 类别4 第3部分 试验方法》.pdf EN 16261-3-2012 en Pyrotechnic articles - Fireworks Category 4 - Part 3 Test methods《烟火用品 烟花 类别4 第3部分 试验方法》.pdf
  • 相关搜索

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

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