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

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

1、二级 C 语言-178 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.下列给定程序中,函数 fun 的功能是:找出 100999(含 100 和 999)所有整数中各位上数字之和为 x(x为正整数)的整数,并输出;符合条件的整数个数作为函数值返回。 例如,当 x 值为 5 时,100999 各位上数字之和为 5 的整数有:104,113,122,131,140,203,212,221,230,302,311,320,401,410,500,共有 15 个。当 x 值为 27 时,各位数字之和为 27 的整数是:999,只有 1 个。 请

2、在下划线处填入正确的内容,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h int fun(int x) int n,s1,s2,s3,t; n=0; t=100; /*found*/ while(t= 1) /*found*/ s1=t%10;s2=( 2)%10; s3=t/100; /*found*/ if(s1+s2+s3= 3) (printf(“%d“,t); n+; t+; return n; main() (int x=-1; while(x0) printf(“Please input(x0

3、); scanf(“%d“,x); printf(“/nThe result is:%d/n“,fun(x); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:从低位开始依次取出长整型变量 s 中偶数位上的数,构成一个新数放在 t 中。高位仍在高位,低位仍在低位。 例如,当 s 中的数为 7654321 时,t 中的数为 642。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h /*found*/ void fun(l

4、ong s,long t) (long s1=10; s/=10; *t=s%10; /*found*/ while(s0) s=s/100; *t=s%10*s1+*t; s1=s1 *10; main() long s,t; printf(“/nPlease enter s:“);scanf(“%ld“,s); fun(s,t); printf(“The result is:%ld/n“,t); (分数:30.00)_三、程序设计题(总题数:1,分数:40.00)3.学生的记录由学号和成绩组成,N 名学生的数据已放入主函数中的结构体数组 S 中。请编写函数 fun,其功能是:按分数降序排列

5、学生的记录,高分在前,低分在后。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 试题程序: #includestdio.h #define N 16 typedef struct char num10; int s; STREC; void fun(STREC a) void main() STREC sN=“GA005“,85,“GA003“,76,“GA002“,69, “GA004“,85,“GA001“,91,“GA007“,72, “GA008“,64,“GA006“,87,“GA015“,85, “

6、GA013“,91,“GA012“,64,“GA014“,91, “GA011“,66,“GA017“,64,“GA018“,64, “GA016“,72; int i; fun(s); printf(“The data after sorted:/n“); for(i=0;iN;i+) if(i%4=0)/*每行输出 4 个学生记录*/ printf(“/n“); printf(“%s%4d“,si.num,si.s); printf(“/n“); (分数:40.00)_二级 C 语言-178 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)

7、1.下列给定程序中,函数 fun 的功能是:找出 100999(含 100 和 999)所有整数中各位上数字之和为 x(x为正整数)的整数,并输出;符合条件的整数个数作为函数值返回。 例如,当 x 值为 5 时,100999 各位上数字之和为 5 的整数有:104,113,122,131,140,203,212,221,230,302,311,320,401,410,500,共有 15 个。当 x 值为 27 时,各位数字之和为 27 的整数是:999,只有 1 个。 请在下划线处填入正确的内容,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程

8、序: #includestdio.h int fun(int x) int n,s1,s2,s3,t; n=0; t=100; /*found*/ while(t= 1) /*found*/ s1=t%10;s2=( 2)%10; s3=t/100; /*found*/ if(s1+s2+s3= 3) (printf(“%d“,t); n+; t+; return n; main() (int x=-1; while(x0) printf(“Please input(x0:“); scanf(“%d“,x); printf(“/nThe result is:%d/n“,fun(x); (分数:

9、30.00)解析:999 t/10 x 考点 本题关键字有:while 循环语句;数 n 各位上数值的表示方法;if 语句。三位数 n 的个位、十位、百位分别用 n%10、n/10%10、n/100 表示。 解析 填空 1:根据题意要找出 100999 之间且包含 100 和 999 符合要求的数,所以循环条件是 t=999。 填空 2:三位数的十位存放在变量 s2 中,所以填入 s2=(t/10)%10;。 填空 3:题目要求找出各位上数字之和为 x 的整数,所以条件表达式是 s1+s2+s3=x。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:从低

10、位开始依次取出长整型变量 s 中偶数位上的数,构成一个新数放在 t 中。高位仍在高位,低位仍在低位。 例如,当 s 中的数为 7654321 时,t 中的数为 642。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h /*found*/ void fun(long s,long t) (long s1=10; s/=10; *t=s%10; /*found*/ while(s0) s=s/100; *t=s%10*s1+*t; s1=s1 *10; main() long s,t;

11、printf(“/nPlease enter s:“);scanf(“%ld“,s); fun(s,t); printf(“The result is:%ld/n“,t); (分数:30.00)_正确答案:()解析:void fun(long s, long*t) while(s0) 考点 本题关键字有:函数定义;while 循环语句。 解析 (1)主函数中给函数 fun 传递的参数为指针类型,所以形参与实参类型相同也为指针类型。 (2)从 s 中的数上取数并组合成一个新数通过 while 循环完成,所以循环条件为 s0。三、程序设计题(总题数:1,分数:40.00)3.学生的记录由学号和成绩

12、组成,N 名学生的数据已放入主函数中的结构体数组 S 中。请编写函数 fun,其功能是:按分数降序排列学生的记录,高分在前,低分在后。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 试题程序: #includestdio.h #define N 16 typedef struct char num10; int s; STREC; void fun(STREC a) void main() STREC sN=“GA005“,85,“GA003“,76,“GA002“,69, “GA004“,85,“GA001“

13、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; fun(s); printf(“The data after sorted:/n“); for(i=0;iN;i+) if(i%4=0)/*每行输出 4 个学生记录*/ printf(“/n“); printf(“%s%4d“,si.num,si.s); printf(“/n“); (分数:40.00)_正确答案:()解析:

14、Void fun (STREC a) int i,j; STREC t; for(i=1;iN;i+) /*用冒泡法进行排序,进行 N-1 次比较*/ for(j=0;jN-1;j+) /*在每一次比较中要进行 N-1 次两两比较*/ if(aj.saj+1.s) t=aj;aj=aj+1; aj+1=t; /*按分数的高低排列学生的记录,高分在前*/ 考点 本题关键字有:排序算法;结构体类型。 解析 对 N 个数进行排序的算法很多,其中冒泡算法比较简单。冒泡法用双层 for 循环和 if 判断语句来实现,外层循环控制需比较的轮数,内层循环控制两两比较。 常见排序算法有冒泡法、选择法、插入法。

15、冒泡排序算法:两两比较待排序相邻数据元素的大小,若两个数据元素处于反序则进行交换,直到没有反序的数据元素为止;选择排序算法:在要排序的一组数中,选出最大或最小的数与第一个位置的数进行交换,再在剩下的数中找出最大或最小的数与第二个位置的数进行交换,依次类推,直至最后两个数比较完成;插入排序算法:先对两个数进行排序,然后把第三个数插入前两个数中,这三个数有序,依次把后面的数插入完。对整型一维数组 aN进行升序排序各种算法实现如下: 冒泡法: for(int i=0;iN-1;i+) for(int j=0;jN-1-i;j+) if(ajaj+1) t=aj;aj=aj+1;aj+1=t; 选择法: for(int i=0;iN-1;i+) p=i; for(j=i+1;jN;j+) if(apaj) p=j; if(p!=i) t=ai;ai=ap;ap=t; 插入法: for(i=1;iN;i+) t=ai; for(j=i-1;ajtj=0;j-) aj+1=aj; aj+1=t;

展开阅读全文
相关资源
猜你喜欢
  • ETSI ETS 300 222-1993 Terminal Equipment (TE) Framework of Videotex Terminal Protocols《终端设备(TE) 可视图文终端协议框架》.pdf ETSI ETS 300 222-1993 Terminal Equipment (TE) Framework of Videotex Terminal Protocols《终端设备(TE) 可视图文终端协议框架》.pdf
  • ETSI ETS 300 223-1993 Terminal Equipment (TE) Syntax-Based Videotex Common End-to-End Protocols《终端设备(TE) 基于句法的可视图文协议一般端到端协议》.pdf ETSI ETS 300 223-1993 Terminal Equipment (TE) Syntax-Based Videotex Common End-to-End Protocols《终端设备(TE) 基于句法的可视图文协议一般端到端协议》.pdf
  • ETSI ETS 300 224-1998 Electromagnetic Compatibility and Radio Spectrum Matters (ERM) On-Site Paging Service Technical and Functional Characteristics for On-Site Paging Systems Incl.pdf ETSI ETS 300 224-1998 Electromagnetic Compatibility and Radio Spectrum Matters (ERM) On-Site Paging Service Technical and Functional Characteristics for On-Site Paging Systems Incl.pdf
  • ETSI ETS 300 224-1998 Electromagnetic Compatibility and Radio Spectrum Matters (ERM) On-Site Paging Service Technical and Functional Characteristics for On-Site Paging Systems Incl_1.pdf ETSI ETS 300 224-1998 Electromagnetic Compatibility and Radio Spectrum Matters (ERM) On-Site Paging Service Technical and Functional Characteristics for On-Site Paging Systems Incl_1.pdf
  • ETSI ETS 300 230-1996 Radio Equipment and Systems (RES) Land Mobile Service Binary Interchange of Information and Signalling (BIIS) at 1 200 Bits s (BIIS 1 200) (Second Edtion)《无线电.pdf ETSI ETS 300 230-1996 Radio Equipment and Systems (RES) Land Mobile Service Binary Interchange of Information and Signalling (BIIS) at 1 200 Bits s (BIIS 1 200) (Second Edtion)《无线电.pdf
  • ETSI ETS 300 230-1996 Radio Equipment and Systems (RES) Land Mobile Service Binary Interchange of Information and Signalling (BIIS) at 1 200 Bits s (BIIS 1 200) (Second Edtion)《无线电_1.pdf ETSI ETS 300 230-1996 Radio Equipment and Systems (RES) Land Mobile Service Binary Interchange of Information and Signalling (BIIS) at 1 200 Bits s (BIIS 1 200) (Second Edtion)《无线电_1.pdf
  • ETSI ETS 300 232-1993 Transmission and Multiplexing (TM) Optical Interfaces for Equipments and Systems Relating to the Synchronous Digital Hierarchy (ITU-T Recommendation G 957 (19.pdf ETSI ETS 300 232-1993 Transmission and Multiplexing (TM) Optical Interfaces for Equipments and Systems Relating to the Synchronous Digital Hierarchy (ITU-T Recommendation G 957 (19.pdf
  • ETSI ETS 300 232-1993 Transmission and Multiplexing (TM) Optical Interfaces for Equipments and Systems Relating to the Synchronous Digital Hierarchy (ITU-T Recommendation G 957 (19_1.pdf ETSI ETS 300 232-1993 Transmission and Multiplexing (TM) Optical Interfaces for Equipments and Systems Relating to the Synchronous Digital Hierarchy (ITU-T Recommendation G 957 (19_1.pdf
  • ETSI ETS 300 233 AMD 1-1995 Integrated Services Digital Network (ISDN) Access Digital Section for ISDN Primary Rate《综合业务数字网(ISDN) ISDN基群速率接入数字段》.pdf ETSI ETS 300 233 AMD 1-1995 Integrated Services Digital Network (ISDN) Access Digital Section for ISDN Primary Rate《综合业务数字网(ISDN) ISDN基群速率接入数字段》.pdf
  • 相关搜索

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

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