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

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

1、二级 C 语言-358 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:调用随机函数产生 20 个互不相同的整数放在形参 a 所指数组中(此数组在主函数中已经置 0)。 请在程序的下划线处填入正确的内容,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdlib.h #includestdio.h #define N 20 void fun(int*a) int i,x,n=0; x=rand()%20; /*found*/ wh

2、ile(n 1) for(i=0;in;i+) /*found*/ if(x=ai) 2; /*found*/ if(i= 3)an=x;n+; x=rand()%20; main() int xN=0,i; fun(x); printf(“The result:/n“); for(i=0;iN;i+) printf(“%4d“,xi); if(i+1)%5=0)printf(“/n“); printf(“/n/n“); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:先从键盘上输入一个 3 行、3 列的矩阵的各个元素的值,然后输出

3、主对角线元素之和。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h void fun() int a33,sum; int i,j; /*found*/ sum=1; for(i=0;i3;i+) for(j=0;j3;j+) /*found*/ scanf(“%d“,aij); fof(i=0;i3;i+) sum=sum+aii; printf(“Sum=%d/n“,sum); void main() fun(); (分数:30.00)三、程序设计题(总题数:1,分数:40.00

4、)3.编写程序,实现矩阵(3 行、3 列)的转置(即行列互换)。 例如,若输入下面的矩阵: 100 200 300 400 500 600 700 800 900 则程序输出: 100 400 700 200 500 800 300 600 900 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 试题程序: #indudestdio.h #includeconio.h #includestdlib.h void fun(int array33) void main() int i,j; int array33=1

5、00,200,300,400,500,600,700,800,900; system(“CLS“); for(i=0;i3;i+) for(j=0;j3;j+) printf(“%7d“,arrayij); printf(“/n“); fun(array); printf(“Converted array:/n“); for(i=0;i3;i+) for(j=0;j3;j+) printf(“%7d”,arrayij); printf(“/n“); (分数:40.00)_二级 C 语言-358 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1

6、给定程序中,函数 fun 的功能是:调用随机函数产生 20 个互不相同的整数放在形参 a 所指数组中(此数组在主函数中已经置 0)。 请在程序的下划线处填入正确的内容,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdlib.h #includestdio.h #define N 20 void fun(int*a) int i,x,n=0; x=rand()%20; /*found*/ while(n 1) for(i=0;in;i+) /*found*/ if(x=ai) 2; /*found*/ if(i= 3

7、)an=x;n+; x=rand()%20; main() int xN=0,i; fun(x); printf(“The result:/n“); for(i=0;iN;i+) printf(“%4d“,xi); if(i+1)%5=0)printf(“/n“); printf(“/n/n“); (分数:30.00)解析:(1)N 或 20 (2)break (3)n 解析 填空 1:变量 n 用于存储数组的下标,要通过 while 语句对数组进行赋值,数组的容量为 20,因此循环条件应为 n20。 填空 2:通过一个 for 循环判断 x 是否与数组中已存的元素重复,若重复则跳出 for

8、循环结束。 填空 3:若 for 循环是由 break 语句结束的,则 x 与数组中的元素重复,此时 i 必然小于 n;若 for 循环是因为循环变量 i 递增到某值,而不再满足循环条件结束的,说明 x 的值与数组中的元素不重复,则此时i 的值等于 n。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:先从键盘上输入一个 3 行、3 列的矩阵的各个元素的值,然后输出主对角线元素之和。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h void f

9、un() int a33,sum; int i,j; /*found*/ sum=1; for(i=0;i3;i+) for(j=0;j3;j+) /*found*/ scanf(“%d“,aij); fof(i=0;i3;i+) sum=sum+aii; printf(“Sum=%d/n“,sum); void main() fun(); (分数:30.00)解析:(1)sum=0; (2)scanf(“%d“, 解析 该题考查对循环语句的掌握和对数组概念的理解。本题的解题思路为:先从键盘输入一个 33 矩阵,然后循环累加,执行循环语句中的 sumsum+aii;。因为变量 sum 用来存放

10、累加后的结果,所以应对其初始化为 0。第二处错误考查标准输入函数 scanf 的格式,被赋值的变量前要加上取地址符“ int array33=100,200,300,400,500,600,700,800,900; system(“CLS“); for(i=0;i3;i+) for(j=0;j3;j+) printf(“%7d“,arrayij); printf(“/n“); fun(array); printf(“Converted array:/n“); for(i=0;i3;i+) for(j=0;j3;j+) printf(“%7d”,arrayij); printf(“/n“); (分数:40.00)_正确答案:()解析:void fun (int array33) int i,j,t; for(i=0;ifor(j=i+1;j3;j+) t=arrayij; arrayij=arrayji; arrayji=t; 解析 要实现矩阵转置,即将右上角数组元素和左下角数组元素对换,本题通过数组元素交换方法,完成矩阵转置操作。 因为对矩阵转置后仍然存回其本身,所以只能循环矩阵中的一个角(本程序是右上半三角)。控制右上半三角的方法是在内层循环中循环变量 j 从 i+1 或 i 开始。

展开阅读全文
相关资源
猜你喜欢
  • ASTM A1064 A1064M-2017 Standard Specification for Carbon-Steel Wire and Welded Wire Reinforcement Plain and Deformed for Concrete《混凝土的平整和变形的碳质钢丝绳和焊接线缆加固的标准规格》.pdf ASTM A1064 A1064M-2017 Standard Specification for Carbon-Steel Wire and Welded Wire Reinforcement Plain and Deformed for Concrete《混凝土的平整和变形的碳质钢丝绳和焊接线缆加固的标准规格》.pdf
  • ASTM A1065 A1065M-2009 Standard Specification for Cold-Formed Electric-Fusion (Arc) Welded High-Strength Low&x2013 Alloy Structural Tubing in Shapes with 50 ksi [345 MPa] Minimum Y.pdf ASTM A1065 A1065M-2009 Standard Specification for Cold-Formed Electric-Fusion (Arc) Welded High-Strength Low&x2013 Alloy Structural Tubing in Shapes with 50 ksi [345 MPa] Minimum Y.pdf
  • ASTM A1065 A1065M-2009(2014) Standard Specification for Cold-Formed Electric-Fusion &40 Arc&41 Welded High-Strength Low&ndash Alloy Structural Tubing in Shapes with 50 ksi [345 MPa.pdf ASTM A1065 A1065M-2009(2014) Standard Specification for Cold-Formed Electric-Fusion &40 Arc&41 Welded High-Strength Low&ndash Alloy Structural Tubing in Shapes with 50 ksi [345 MPa.pdf
  • ASTM A1065 A1065M-2015 Standard Specification for Cold-Formed Electric-Fusion (Arc) Welded High-Strength Low&ndash Alloy Structural Tubing in Shapes with 50 ksi [345 MPa] Minimum Y.pdf ASTM A1065 A1065M-2015 Standard Specification for Cold-Formed Electric-Fusion (Arc) Welded High-Strength Low&ndash Alloy Structural Tubing in Shapes with 50 ksi [345 MPa] Minimum Y.pdf
  • ASTM A1065 A1065M-2018 Standard Specification for Cold-Formed Electric-Fusion (Arc) Welded High-Strength Low&x2013 Alloy Structural Tubing in Shapes with 50 ksi [345 MPa] Minimum Y.pdf ASTM A1065 A1065M-2018 Standard Specification for Cold-Formed Electric-Fusion (Arc) Welded High-Strength Low&x2013 Alloy Structural Tubing in Shapes with 50 ksi [345 MPa] Minimum Y.pdf
  • ASTM A1066 A1066M-2011 Standard Specification for High-Strength Low-Alloy Structural Steel Plate Produced by Thermo-Mechanical Controlled Process (TMCP)《热机械控制工艺(TMCP)加工的高强度低合金结构钢板的.pdf ASTM A1066 A1066M-2011 Standard Specification for High-Strength Low-Alloy Structural Steel Plate Produced by Thermo-Mechanical Controlled Process (TMCP)《热机械控制工艺(TMCP)加工的高强度低合金结构钢板的.pdf
  • ASTM A1066 A1066M-2011(2015)e1 Standard Specification for High-Strength Low-Alloy Structural Steel Plate Produced by Thermo-Mechanical Controlled Process (TMCP)《使用热机械控制工艺 (TMCP) 生产.pdf ASTM A1066 A1066M-2011(2015)e1 Standard Specification for High-Strength Low-Alloy Structural Steel Plate Produced by Thermo-Mechanical Controlled Process (TMCP)《使用热机械控制工艺 (TMCP) 生产.pdf
  • ASTM A1066 A1066M-2011(2015)e2 Standard Specification for High-Strength Low-Alloy Structural Steel Plate Produced by Thermo-Mechanical Controlled Process (TMCP)《使用热机械控制工艺(TMCP)生产的高.pdf ASTM A1066 A1066M-2011(2015)e2 Standard Specification for High-Strength Low-Alloy Structural Steel Plate Produced by Thermo-Mechanical Controlled Process (TMCP)《使用热机械控制工艺(TMCP)生产的高.pdf
  • ASTM A1067 A1067M-2012 Standard Specification for Test Coupons for Steel Castings《钢铸件试样标准规格》.pdf ASTM A1067 A1067M-2012 Standard Specification for Test Coupons for Steel Castings《钢铸件试样标准规格》.pdf
  • 相关搜索

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

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