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

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

1、二级 C 语言-185 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充函数 proc(),该函数的功能是:把数组 aa 中元素下标为奇数的元素按从大到小的顺序重新保存在原数组中,其他元素位置不变。 例如,若数组 aa 中的元素为:“45 65 40 32 13 57 88 90 67 99”,则输出结果为:“45 99 40 90 13 65 88 57 67 32”。 注意:部分源程序中的给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序:

2、#includestdlib.h #includestdio.h #define M 10 void proc(int aa) int i, j, t; for( 1; iM; i=i+2) for(j=i; jM; j=j+2) if(aaiaaj) 2; aaj=aai; 3; void main() int i; int aaM=45, 65, 40, 32, 13, 57, 88, 90, 67, 99; system(“CLS“); printf(“/n*original list*/n“); for(i=0; iM; i+) printf(“%4d“, aai); proc(aa)

3、; printf(“/n*new list*/n“); for(i=0; iM; i+) printf(“%4d“, aai); (分数:30.00)二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中,函数 proc()的功能是:给定 n 个实数,输出平均值,并统计平均值以上(含平均值)的实数个数。 例如,n=8 时,输入 90.009,179.623,167.575,100.051,6.092,154.986,12.432,45.765,所得平均值为 94.566635,在平均值以上的实数个数应为 4。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函

4、数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h int proc(float x, int n) /*found* int j, c=0; float xa=0.0; for(j=0; jn; j+) xa+=xj/n; printf(“ave=%f/n“, xa); for(j=0; jn; j+) if(xj=xa) c+; retUrn c; void main() float str100=90.009, 179.623, 167.575, 100.051, 6.092, 154.

5、986, 12.432, 45.765; system(“CLS“); printf(“%d/n“, proc(str, 8); (分数:40.00)_三、程序设计题(总题数:1,分数:30.00)3.请编写函数 proc(),该函数的功能是:实现 B=A+A“,即把矩阵 A 加上 A 的转置,存放在矩阵 B 中。计算结果在 main()函数中输出。 例如,输入下面矩阵: 1 1 1 4 4 4 7 7 7 其转置矩阵为: 1 4 7 1 4 7 1 4 7 则程序输出: 2 5 8 5 8 11 8 11 14 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅

6、在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includeconio.h #includestdlib.h void proc(int a33, int b33) void main() int arr33=1, 1, 1, 4, 4, 4, 7, 7, 7, t33; int i, j; system(“CLS“); proc(art, t); for(i=0; i3; i+) for(j=0; j3; j+) printf(“%7d“, tij); printf(“/n“); (分数:30.00)_二级 C 语言-185 (1)答案解

7、析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充函数 proc(),该函数的功能是:把数组 aa 中元素下标为奇数的元素按从大到小的顺序重新保存在原数组中,其他元素位置不变。 例如,若数组 aa 中的元素为:“45 65 40 32 13 57 88 90 67 99”,则输出结果为:“45 99 40 90 13 65 88 57 67 32”。 注意:部分源程序中的给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #i

8、ncludestdio.h #define M 10 void proc(int aa) int i, j, t; for( 1; iM; i=i+2) for(j=i; jM; j=j+2) if(aaiaaj) 2; aaj=aai; 3; void main() int i; int aaM=45, 65, 40, 32, 13, 57, 88, 90, 67, 99; system(“CLS“); printf(“/n*original list*/n“); for(i=0; iM; i+) printf(“%4d“, aai); proc(aa); printf(“/n*new li

9、st*/n“); for(i=0; iM; i+) printf(“%4d“, aai); (分数:30.00)解析:i=1 t=aaj aai=t解析 按题目中要求将数组中元素下标为奇数的元素按从大到小的顺序排列,所以变量 i 的初始值为 1,因此,第一处填“i=1”;将顺序不符合要求的两元素互换,因此,第二处填“t=aaj”;第三处填“aai=t”。二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中,函数 proc()的功能是:给定 n 个实数,输出平均值,并统计平均值以上(含平均值)的实数个数。 例如,n=8 时,输入 90.009,179.623,167.575,100.

10、051,6.092,154.986,12.432,45.765,所得平均值为 94.566635,在平均值以上的实数个数应为 4。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h int proc(float x, int n) /*found* int j, c=0; float xa=0.0; for(j=0; jn; j+) xa+=xj/n; printf(“ave=%f/n“, xa); for(j=0;

11、jn; j+) if(xj=xa) c+; retUrn c; void main() float str100=90.009, 179.623, 167.575, 100.051, 6.092, 154.986, 12.432, 45.765; system(“CLS“); printf(“%d/n“, proc(str, 8); (分数:40.00)_正确答案:()解析:错误:缺 正确:加 解析 根据 C 语言语法规则,函数体中的所有语句应包含在符号和之间。因此,应在函数proc()的函数后面加上符号。三、程序设计题(总题数:1,分数:30.00)3.请编写函数 proc(),该函数的功能

12、是:实现 B=A+A“,即把矩阵 A 加上 A 的转置,存放在矩阵 B 中。计算结果在 main()函数中输出。 例如,输入下面矩阵: 1 1 1 4 4 4 7 7 7 其转置矩阵为: 1 4 7 1 4 7 1 4 7 则程序输出: 2 5 8 5 8 11 8 11 14 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includeconio.h #includestdlib.h void proc(int a33, int b33) void main(

13、) int arr33=1, 1, 1, 4, 4, 4, 7, 7, 7, t33; int i, j; system(“CLS“); proc(art, t); for(i=0; i3; i+) for(j=0; j3; j+) printf(“%7d“, tij); printf(“/n“); (分数:30.00)_正确答案:()解析:void proc(int a33, int b33) int i, j; for(i=0; i3; i+) /从题目中可知“A“表示的为 a 数组的行与列下标互换得到的数组 for(j=0; j3; j+) bij=aij+aji; /因此把互换的数组与原数组中的和放到 b 数组中 解析 矩阵与其逆置矩阵的关系为:逆置矩阵中某一位置上的元素值为原矩阵中,行下标与列下标互换后的位置上的元素。根据这个特点求出各个位置上逆置矩阵中对应的值,进行相加并放在该位置上。

展开阅读全文
相关资源
猜你喜欢
  • BS 5223-2-1999 Specification for hospital bedding - Combustion modified flexible polyurethane general purpose foam mattress cores - Specification《医院床位规范 燃烧改型的 软聚氨酯 一般用途的泡沫床垫芯规范》.pdf BS 5223-2-1999 Specification for hospital bedding - Combustion modified flexible polyurethane general purpose foam mattress cores - Specification《医院床位规范 燃烧改型的 软聚氨酯 一般用途的泡沫床垫芯规范》.pdf
  • BS 5223-3-1976 Specification for hospital bedding - Flexible polyurethane pillows《医院用床褥规范 第3部分 聚氨基甲酸乙脂软枕》.pdf BS 5223-3-1976 Specification for hospital bedding - Flexible polyurethane pillows《医院用床褥规范 第3部分 聚氨基甲酸乙脂软枕》.pdf
  • BS 5223-4-1976 Specification for hospital bedding - Mattress covers of polyurethane coated nylon《医院用床褥规范 第4部分 覆盖尼龙的聚氨基甲酸乙酯床垫罩》.pdf BS 5223-4-1976 Specification for hospital bedding - Mattress covers of polyurethane coated nylon《医院用床褥规范 第4部分 覆盖尼龙的聚氨基甲酸乙酯床垫罩》.pdf
  • BS 5226-1991 Code of practice for equipment and procedures for the cleaning and disinfecting of milking machine installations《挤奶机械安装清洗和消毒用设备和工序的实用规程》.pdf BS 5226-1991 Code of practice for equipment and procedures for the cleaning and disinfecting of milking machine installations《挤奶机械安装清洗和消毒用设备和工序的实用规程》.pdf
  • BS 5228-2-2009 Code of practice for noise nand vibration control on nconstruction and open sites – nPart 2 Vibration《建筑和露天场地的噪声和振动控制用实施规程 振动》.pdf BS 5228-2-2009 Code of practice for noise nand vibration control on nconstruction and open sites – nPart 2 Vibration《建筑和露天场地的噪声和振动控制用实施规程 振动》.pdf
  • BS 5228-2-2009+A1-2014 Code of practice for noise and vibration control on construction and open sites Part 2 Vibration《建筑工地和露天工地噪声和振动控制惯例 第2部分 振动》.pdf BS 5228-2-2009+A1-2014 Code of practice for noise and vibration control on construction and open sites Part 2 Vibration《建筑工地和露天工地噪声和振动控制惯例 第2部分 振动》.pdf
  • BS 5229-1975 Method for determination of tuft withdrawal force of carpets《地毯毛撮分离力测定方法》.pdf BS 5229-1975 Method for determination of tuft withdrawal force of carpets《地毯毛撮分离力测定方法》.pdf
  • BS 5234-1-1992 Partitions (including matching linings) - Code of practice for design and installation《隔墙(包括覆面板) 第1部分 设计和安装实施规程》.pdf BS 5234-1-1992 Partitions (including matching linings) - Code of practice for design and installation《隔墙(包括覆面板) 第1部分 设计和安装实施规程》.pdf
  • BS 5234-2-1992 Partitions (including matching linings) - Specification for performance requirements for strength and robustness including methods of test《隔墙(包括覆面板) 第2部分 隔墙强度和坚固性要求(.pdf BS 5234-2-1992 Partitions (including matching linings) - Specification for performance requirements for strength and robustness including methods of test《隔墙(包括覆面板) 第2部分 隔墙强度和坚固性要求(.pdf
  • 相关搜索

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

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