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

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

1、二级 C 语言-231 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:如果数组 arr 的前一个元素比后一个元素小,则把它保存在数组 bb 中并输出。 例如,若数组中的元素为:“40,68,62,33,35,52,48,95,66,73”,则输出:“40,33,35,48,66”。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h

2、 #define M 10 void main() int i,n=0; int arrM=40,68,62,33,35,52,48,95,66,73; int bbM; system(“CLS“); for(i=0;i 1;i+) if(arriarri+1) 2; printf(“/n*display bb*/n“); for(i=0;in;i+) printf(“bb%d=%2d“, 3); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.给定程序中,函数 proc()的功能是:使数组中的元素的值缩小 5 倍。 请修改程序中的错误,使它能得出正确的结果。 注意:不要

3、改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includestdio.h #includeconio.h float m10; /*found* int proc(void) int j; printf(“In subfunc after calling/n“); for(j=0;j10;j+) /*found* printf(“%f“,mj%5); void main() int i; printf(“In main before calling/n“); for(i=0;i10;i+) mi=i+20; printf(“%

4、f“,mi); proc(); printf(“/nIn main after calling/n“); for(i=0;i10;i+) printf(“%f“,mi/5); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.学生的记录由学号和成绩组成,M 名学生的数据已在主函数中放入结构体数组 stu 中,请编写函数proc(),其功能是:按分数的高低排列学生的记录,高分在前。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #define M

5、 16 typedef struct char num10; int s; ) STREC; void proc(STREC a) int i,j; STREC t; for(i=1;jM;i+) /*用冒泡法按从高到低排序*/ for(j=0;jM-1;j+) if(aj.saj+1.s)/*按分数的高低排列学生的记录,高分在前*/ t=aj;aj=aj+1;aj+1=t; void main() STREC stuM=“GA005“,85,“GA003“,76, “GA002“,69,“GA004“,85,“GA001“,91, “GA007“,72,“GA008“,64,“GA006“,

6、87, “GA015“,85,“GA013“,91,“GA012“,64, “GA014“,91,“GA011“,66,“GA017“,64, “GA018“,64,“GA016“,72; int i; proc(stu); printf(“The data after sorted:/n“); for(i=0;iM;i+) if(i%4=0) /每行输出 4 个学生记录 printf(“/n“); printf(“%s%4d“,stui.num,stui.s); printf(“/n“); (分数:40.00)_二级 C 语言-231 答案解析(总分:100.00,做题时间:90 分钟)一、

7、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:如果数组 arr 的前一个元素比后一个元素小,则把它保存在数组 bb 中并输出。 例如,若数组中的元素为:“40,68,62,33,35,52,48,95,66,73”,则输出:“40,33,35,48,66”。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h #define M 10 void main() int i,n=0; int

8、arrM=40,68,62,33,35,52,48,95,66,73; int bbM; system(“CLS“); for(i=0;i 1;i+) if(arriarri+1) 2; printf(“/n*display bb*/n“); for(i=0;in;i+) printf(“bb%d=%2d“, 3); (分数:30.00)解析:M-1 bbn+=arri i,bbi解析 由整个 for 循环可知,变量 i 为数组 arr 的下标,题目中要求取出前一个元素比后一个元素小的元素,所以只需要判断前 M-1 个元素即可。因此,第一处填“M-1”;如果第 i 个元素比第 i+1 个元素小

9、将第 i 个元素放入数组 bb 中,因此,第二处填“bbn+=arri”。最后,要输出数组 bb 中的每一个元素。因此,第三处填“i,bbi”。二、程序改错题(总题数:1,分数:30.00)2.给定程序中,函数 proc()的功能是:使数组中的元素的值缩小 5 倍。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includestdio.h #includeconio.h float m10; /*found* int proc(void) int j; printf(“I

10、n subfunc after calling/n“); for(j=0;j10;j+) /*found* printf(“%f“,mj%5); void main() int i; printf(“In main before calling/n“); for(i=0;i10;i+) mi=i+20; printf(“%f“,mi); proc(); printf(“/nIn main after calling/n“); for(i=0;i10;i+) printf(“%f“,mi/5); (分数:30.00)解析:错误:int proc(void) 正确:void proc(void)

11、错误:printf(“%f“,mj%5); 正确:printf(“%f“,mj/5); 解析 由主函数中的函数调用可知,函数 proc()没有返回值。因此,“int proc(void)”应改为“void proc(void)”。题目中要求使数组中元素的值缩小到 1/5,而不是对5 取余。因此,“printf(“%f“,mj%5);”应改为“printf(“%f“,mj/5);”。三、程序设计题(总题数:1,分数:40.00)3.学生的记录由学号和成绩组成,M 名学生的数据已在主函数中放入结构体数组 stu 中,请编写函数proc(),其功能是:按分数的高低排列学生的记录,高分在前。 注意:部

12、分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #define M 16 typedef struct char num10; int s; ) STREC; void proc(STREC a) int i,j; STREC t; for(i=1;jM;i+) /*用冒泡法按从高到低排序*/ for(j=0;jM-1;j+) if(aj.saj+1.s)/*按分数的高低排列学生的记录,高分在前*/ t=aj;aj=aj+1;aj+1=t; void main() STRE

13、C stuM=“GA005“,85,“GA003“,76, “GA002“,69,“GA004“,85,“GA001“,91, “GA007“,72,“GA008“,64,“GA006“,87, “GA015“,85,“GA013“,91,“GA012“,64, “GA014“,91,“GA011“,66,“GA017“,64, “GA018“,64,“GA016“,72; int i; proc(stu); printf(“The data after sorted:/n“); for(i=0;iM;i+) if(i%4=0) /每行输出 4 个学生记录 printf(“/n“); printf(“%s%4d“,stui.num,stui.s); printf(“/n“); (分数:40.00)_正确答案:()解析:void proc(STREC a) int i,j; STREC t; for(i=1;iM;i+) /用冒泡法按从高到低排序 for(j=0,jM-1;j+) if(aj.saj+1.s) /按分数的高低排列学生的记录,高分在前 t=aj;aj=aj+1;aj+1=t; 解析 要按分数的高低排列学生的记录,可以使用冒泡排序法。将每一个学生的成绩与其他学生的成绩相比较,对不符合要求的记录交换位置。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 2243-4-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 4 Metal-Honeycomb Core Flatwise Tensile Test Edition P 1《航空航天系列非金属物质结构用粘结剂.第4部分.pdf AECMA PREN 2243-4-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 4 Metal-Honeycomb Core Flatwise Tensile Test Edition P 1《航空航天系列非金属物质结构用粘结剂.第4部分.pdf
  • AECMA PREN 2243-5-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 5 Ageing Tests Edition P 1《航空航天系列非金属物质结构用粘结剂.第5部分 老化试验.P1版》.pdf AECMA PREN 2243-5-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 5 Ageing Tests Edition P 1《航空航天系列非金属物质结构用粘结剂.第5部分 老化试验.P1版》.pdf
  • AECMA PREN 2243-6-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 6 Determination of Shear Stress and Shear Strain Edition P 2《航空航天系列非金属物质结构用粘结剂..pdf AECMA PREN 2243-6-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 6 Determination of Shear Stress and Shear Strain Edition P 2《航空航天系列非金属物质结构用粘结剂..pdf
  • AECMA PREN 2245-1984 Pipelines for Liquids and Gases Definitions Aerospace Series Edition 2《液体和气体管道定义2版》.pdf AECMA PREN 2245-1984 Pipelines for Liquids and Gases Definitions Aerospace Series Edition 2《液体和气体管道定义2版》.pdf
  • AECMA PREN 2247-1977 Steel FE-PL43S 650 MPa Less Than or Equal to Rm Less Than or Equal to 850 MPa Tubes for Structures 0 5 mm Less Than or Equal to a Less Than or Equal to 12 mm dd.pdf AECMA PREN 2247-1977 Steel FE-PL43S 650 MPa Less Than or Equal to Rm Less Than or Equal to 850 MPa Tubes for Structures 0 5 mm Less Than or Equal to a Less Than or Equal to 12 mm dd.pdf
  • AECMA PREN 2251-1977 Steel FE-PL52 S Rm Greater Than or Equal to 700 MPa Tubes for Structures 0 8 mm Less Than or Equal to a Less Than or Equal to 12 5 mm d Greater Than or Equal t.pdf AECMA PREN 2251-1977 Steel FE-PL52 S Rm Greater Than or Equal to 700 MPa Tubes for Structures 0 8 mm Less Than or Equal to a Less Than or Equal to 12 5 mm d Greater Than or Equal t.pdf
  • AECMA PREN 2252-1977 Steel FE-PL52 S 1080 MPa Less Than or Equal to Rm Less Than or Equal to 1250 MPa Hand and Die Forgings De Less Than or Equal to 100 mm Aerospace Series Edition.pdf AECMA PREN 2252-1977 Steel FE-PL52 S 1080 MPa Less Than or Equal to Rm Less Than or Equal to 1250 MPa Hand and Die Forgings De Less Than or Equal to 100 mm Aerospace Series Edition.pdf
  • AECMA PREN 2253-1984 Flexible Hose Assemblies in Elastomers - Type 1 - Technical Specification Aerospace Series Edition 1《航空航天系列软管弹性组件1类技术规范.第1版》.pdf AECMA PREN 2253-1984 Flexible Hose Assemblies in Elastomers - Type 1 - Technical Specification Aerospace Series Edition 1《航空航天系列软管弹性组件1类技术规范.第1版》.pdf
  • AECMA PREN 2255-1996 Aerospace Series Flexible Hose Assemblies in Polytetrafluoroethylene (PTFE) - Type 3 - Technical Specification Edition P 1 Corrigendum 2 28 97 Corrigendum 2 7 .pdf AECMA PREN 2255-1996 Aerospace Series Flexible Hose Assemblies in Polytetrafluoroethylene (PTFE) - Type 3 - Technical Specification Edition P 1 Corrigendum 2 28 97 Corrigendum 2 7 .pdf
  • 相关搜索

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

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