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

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

1、二级 C语言机试-178 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)下列给定的程序中,函数 fun()的功能是:求输入的两个数中较小的数。例如:输入 5 10,结果为 min is 5。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在行线上填入所编写的若干表达式或语句。试题源程序 #include stdio.h#include conio.hint fun(int x, (1) )int z;z=xy (2) x:y;return(z);main()int a,b,c;scanf(“%d,%d/n“, (

2、3) );c=fun(a,b);printf(“min is % d“,c);(分数:30.00)填空项 1:_填空项 1:_填空项 1:_二、程序修改题(总题数:1,分数:30.00)1.下列给定程序中,函数 fun()的功能是求出数组中最小数和次最小数,并把最小数和 a0中的数对调,次最小数和 a1中的数对调。请改正程序中的错误,使它能得到正确结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。试题源程序 #includestdio.h#includeconio.h#define N 20void fun(int * a,intn)int i,m,t,k;/*foun

3、d*/for(i=0;in;i+)m=i;for(k=i;kn;k+)if(akam)/*found*/k=m;t=ai;ai=am;am=t;(分数:30.00)_三、程序设计题(总题数:1,分数:40.00)2.下列程序定义了 NN的二维数组,并在主函数中赋值。请编写一个函数 fun(),函数的功能是:求数组周边元素的平方和并作为函数值返回给主函数中的值。例如,若数组 a中的值为0 1 2 7 91 11 21 5 52 21 6 11 19 7 9 10 25 4 1 4 1则返回主程序后 s的值应为 310。注意:部分原程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在

4、函数 fun的花括号中填入所编写的若干语句。试题源程序 #includestdio.h#includeconio.h#includestdlib.h#define N 5int fun(int wN)main()int aNN=0,1,2,7,9,1,11,21,5,5,2,21,6,11,1,9,7,9,10,2,5,4,1,4,1;int i,j;int s;clrscr();printf(“*The array*/n“);for(i=0;iN;i+)for(j=0;jN;j+)printf(“%4d“,aij);printf(“/n“);S=fun(a):printf(“*THE RES

5、ULT*/n“);printf(“The sum is:%d/n“,s);(分数:40.00)_二级 C语言机试-178 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)下列给定的程序中,函数 fun()的功能是:求输入的两个数中较小的数。例如:输入 5 10,结果为 min is 5。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在行线上填入所编写的若干表达式或语句。试题源程序 #include stdio.h#include conio.hint fun(int x, (1) )int z;z=xy (2) x

6、:y;return(z);main()int a,b,c;scanf(“%d,%d/n“, (3) );c=fun(a,b);printf(“min is % d“,c);(分数:30.00)填空项 1:_ (正确答案:int y)解析:填空项 1:_ (正确答案:?)解析:填空项 1:_ (正确答案:a,b)解析:解析 填空 1:根据题目的意思,这里应该是予函数的参数声明部分,C 语言规定,在函数的形参中不允许出现 int x,y 之类的语句,必须指定每一个参数的类型,所以不能直接写 y。填空 2:根据题目的意思,此处是使用三目运算符“?:”比较两个数的大小,使用规则是如果运算符前面的表达式

7、中哪个变量成立,则整个式子就取运算符后面的哪个变量。填空 3:由算法可以看出,此处是输入变量 a和 b的值,因为使用了 scanf函数,所以应该使用符号“”,注意两个变量之间“,”不能省略。二、程序修改题(总题数:1,分数:30.00)1.下列给定程序中,函数 fun()的功能是求出数组中最小数和次最小数,并把最小数和 a0中的数对调,次最小数和 a1中的数对调。请改正程序中的错误,使它能得到正确结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。试题源程序 #includestdio.h#includeconio.h#define N 20void fun(int *

8、a,intn)int i,m,t,k;/*found*/for(i=0;in;i+)m=i;for(k=i;kn;k+)if(akam)/*found*/k=m;t=ai;ai=am;am=t;(分数:30.00)_正确答案:(1)错误:for(i=0;in;i+)正确:for(i=0;i2;i+)(2)错误:k=m;正确:m=k;)解析:解析 错误 1:由于题目要求将最小数和次最小数分别与和 a0中 a1的数对调,因此这层循环只需循环两次。错误 2:赋值语句的执行方向是从右到左,即把右边的值赋给左边的变量。三、程序设计题(总题数:1,分数:40.00)2.下列程序定义了 NN的二维数组,并在

9、主函数中赋值。请编写一个函数 fun(),函数的功能是:求数组周边元素的平方和并作为函数值返回给主函数中的值。例如,若数组 a中的值为0 1 2 7 91 11 21 5 52 21 6 11 19 7 9 10 25 4 1 4 1则返回主程序后 s的值应为 310。注意:部分原程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入所编写的若干语句。试题源程序 #includestdio.h#includeconio.h#includestdlib.h#define N 5int fun(int wN)main()int aNN=0,1,2,7,9,1,

10、11,21,5,5,2,21,6,11,1,9,7,9,10,2,5,4,1,4,1;int i,j;int s;clrscr();printf(“*The array*/n“);for(i=0;iN;i+)for(j=0;jN;j+)printf(“%4d“,aij);printf(“/n“);S=fun(a):printf(“*THE RESULT*/n“);printf(“The sum is:%d/n“,s);(分数:40.00)_正确答案:(int fun(int wN)int i,j,k=0;int s=0;for(i=0;iN:i+)for(j=0;jN;j+)if(i=0|i=N-1|j=0|j=N-1)s=s+wij*wij;return s;)解析:解析 该题采用逐一判断的方式,周边元素的下标一定有 0或 N-1,且只要下标中有一个为 0或N-1,则它一定是周边元素。

展开阅读全文
相关资源
猜你喜欢
  • GOST 4 167-1985 System of product-quality indices Large electrical rotating machines with frame number above 355 Nomenclature of indices《外形尺寸大于355的大型旋转电机 指标项目》.pdf GOST 4 167-1985 System of product-quality indices Large electrical rotating machines with frame number above 355 Nomenclature of indices《外形尺寸大于355的大型旋转电机 指标项目》.pdf
  • GOST 4 168-1985 System of production quality indexes Ultracentrifuges and rotors preparative Nomenclature of indexes《超速离心机和切片转子 指标项目》.pdf GOST 4 168-1985 System of production quality indexes Ultracentrifuges and rotors preparative Nomenclature of indexes《超速离心机和切片转子 指标项目》.pdf
  • GOST 4 17-1980 Quality rating system Rubber seals Quality characteristics nomenclature《接触型橡胶密封 指标项目》.pdf GOST 4 17-1980 Quality rating system Rubber seals Quality characteristics nomenclature《接触型橡胶密封 指标项目》.pdf
  • GOST 4 170-1985 System of product-quality indices Analysers for aerosols of solid and granular materials Nomenclature of indices《固体和散体物质气溶胶分析仪 指标项目》.pdf GOST 4 170-1985 System of product-quality indices Analysers for aerosols of solid and granular materials Nomenclature of indices《固体和散体物质气溶胶分析仪 指标项目》.pdf
  • GOST 4 171-1985 Product-quality index system Turbo-generators whater-wheel generators synchronous condensers and their excitation systems Nomenclature of indices《产品质量指标系统 涡轮发电机 水轮发.pdf GOST 4 171-1985 Product-quality index system Turbo-generators whater-wheel generators synchronous condensers and their excitation systems Nomenclature of indices《产品质量指标系统 涡轮发电机 水轮发.pdf
  • GOST 4 172-1985 System of product-quality indices Power capacitors capacitor installations Nomenclature of indices《电力电容器 电容器装置 指标项目》.pdf GOST 4 172-1985 System of product-quality indices Power capacitors capacitor installations Nomenclature of indices《电力电容器 电容器装置 指标项目》.pdf
  • GOST 4 173-1985 System of product-quality indices Factory-assembled switch-gears for voltage above 1000 V Nomenclature of indices《产品质量指标系统 用于1000 V以上高压的工厂组装开关设备 目录术语》.pdf GOST 4 173-1985 System of product-quality indices Factory-assembled switch-gears for voltage above 1000 V Nomenclature of indices《产品质量指标系统 用于1000 V以上高压的工厂组装开关设备 目录术语》.pdf
  • GOST 4 176-1985 System of product-quality indeces High-voltage electrical apparatus Nomenclature of indices《高压电器 指标项目》.pdf GOST 4 176-1985 System of product-quality indeces High-voltage electrical apparatus Nomenclature of indices《高压电器 指标项目》.pdf
  • GOST 4 177-1985 Product-quality index system Nondectructive testing instruments Nomenclature of indices《材料和制品的无损质量检验仪器 指标项目》.pdf GOST 4 177-1985 Product-quality index system Nondectructive testing instruments Nomenclature of indices《材料和制品的无损质量检验仪器 指标项目》.pdf
  • 相关搜索

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

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