【计算机类职业资格】二级C语言分类模拟题241及答案解析.doc

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

1、二级 C语言分类模拟题 241及答案解析(总分: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、序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在 下的 BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #includeStdio.h int fun(int x) int n, s1, s2, s3, t; n=0; t=100; /*found*/ while(t=_) /*found*/ s1=t%10; s2=(_)%10; s3=t/100; /*found*/ if(s1+s2+s3=_) printf(“%d“, t); n+; t+; return n; main() int x=-1; while(x0) printf(“Pl

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

4、 void fun(10ng 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“, fun(s, printf(“The result is: %ld/n“, t); (分数:30.00)_三、程序设计题(总题数:1,分数:40.00)3.学生的记录由学号和成绩组成,N 名学生的数据已在主函数中放入结构体数组 s中,请编写函数 fun,它的功能

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

6、7, “GA015“, 85, “GA013“, 91, “GA012“, 64, “GA014“, 91, “GA011“, 66, “GA017“, 64, “GA018“, 64, “GA016“, 72; int i; FILE *out; fun(s); printf(“The data after sorted:/n“); for(i=0; iN; i+) if(i)%4=0)printf(“/n“); printf(“%s %4d “, si.num, si.s); printf(“/n“); out=fopen(“out.dat“, “w“); for(i=0; iN; i+)

7、 if(i)%4=0 fprintf(out, “%4d“, si.s); fprintf(out, “/n“); fclose(out); (分数:40.00)_二级 C语言分类模拟题 241答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun的功能是:找出 100999 之间(含 100和 999)所有整数中各位上数字之和为 x(x为一正整数)的整数,然后输出;符合条件的整数个数作为函数值返回。 例如,当 X值为 5时,100999 之间各位上数字之和为 5的整数有:104、113、122、131、140、203、2

8、12、221、230、302、311、320、401、410、500。共有 15个。当 x值为 27时,各位数字之和为 27的整数是:999。只有 1个。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在 下的 BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #includeStdio.h int fun(int x) int n, s1, s2, s3, t; n=0; t=100; /*found*/ while(t=_) /*found*/ s1=t%10; s2=(_)%10; s3=t/100; /*found*/ if(s1+

9、s2+s3=_) printf(“%d“, t); n+; t+; return n; main() int x=-1; while(x0) printf(“Please input(x0): “); scanf(“%d“, printf(“/nThe result is: %d/n“, fun(x); z (分数:30.00)_正确答案:()解析:(1)999 (2)t/10 (3)x 答案考生文件夹 解析 在 100999 之间(含 100和 999)所有整数中,取 x的个位、十位和百位,可由x%10,x/10 再对 10求余、x/100 分别得到。第一空:是补充 while循环的终止条件

10、题干要求。fun 寻找 100999 之间满足条件的数 x,因此循环终止条件是 999,故第一空处应填“999”。 第二空:“s1=t%10; s2=(_)%10; s3=t/100; ”可知 s1求得 t的个位数,s3 求得 t的百位数,因此 s2是求 t的十位数。(t/10)变量 t变成两位数,再次对 10取余便得到 t的十位数,因此第二空处应为“t/10”。 第三空:“if(s1+s2+s3=_)”是判断 t是否满足题干条件:各位上数字之和为 x,因此第三空处应为“x”。 考点 while 循环控制、if 语句及其构成的选择。二、程序修改题(总题数:1,分数:30.00)2.给定程序

11、MODI1.C中函数 fun的功能是:从低位开始取出长整型变量 s中偶数位上的数,依次构成一个新数放在 t中。高位仍在高位,低位仍在低位。 例如,当 s中的数为:7654321 时,t 中的数为:642。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构! #includestdio.h /*found*/ void fun(10ng 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()

12、long s, t; printf(“/nPlease enter s: “); scanf(“%ld“, fun(s, printf(“The result is: %ld/n“, t); (分数:30.00)_正确答案:()解析:(1)void fun(long s, long *t) (2)while(s0) 答案考生文件夹 解析 函数目的是取出长整型变量 s中偶数位上的数。 (1)第一个标识下的形参 t被定义为一个 long型变量,而对应的主函数中的实参却是一个地址值。因此,t在函数定义中应该被定义为一个指针变量,即“void fun(long s, long t)”改为“void f

13、un(long s, long *t)”。 (2)第二个标识下的 while循环控制表达式“s0”要求 s小于 0才进入循环。而 s的值总是大于 0,因此将“while(s0)”改为“while(s0)”。 考点 while 循环控制、运算符。三、程序设计题(总题数:1,分数:40.00)3.学生的记录由学号和成绩组成,N 名学生的数据已在主函数中放入结构体数组 s中,请编写函数 fun,它的功能是:按分数的高低排列学生的记录,高分在前。 注意:部分源程序在文件 PROG1.C文件中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 #incl

14、udestdio.h #define N 16 typedef struct char hum10; int s; STREC; void fun(STREC a) main() STREC sN=“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

15、 72; int i; FILE *out; fun(s); printf(“The data after sorted:/n“); for(i=0; iN; i+) if(i)%4=0)printf(“/n“); printf(“%s %4d “, si.num, si.s); printf(“/n“); out=fopen(“out.dat“, “w“); for(i=0; iN; i+) if(i)%4=0 fprintf(out, “%4d“, si.s); fprintf(out, “/n“); fclose(out); (分数:40.00)_正确答案:()解析:STREC tmp; int i, j; for(i=0; iN; i+) for(j=i+1; jN; j+) if(ai.saj.s) tmp=ai; ai=aj; aj=tmp; 答案考生文件夹 解析 (1)在 fun函数中,通过循环对成绩记录进行排序。 (2)首次查找到最大的记录,第二次循环查找第二大的记录,依次实现对成绩记录的排序。 考点 结构体数组、循环的嵌套。

展开阅读全文
相关资源
猜你喜欢
  • CNS 15103-2007 Textiles - Determination of abrasion resistance of fabrics by the Martindale method - Part 1  Martindale abrasion testing apparatus《纺织品耐摩损性马丁代尔试验法-第1部:马丁代尔耐摩损试验机》.pdf CNS 15103-2007 Textiles - Determination of abrasion resistance of fabrics by the Martindale method - Part 1 Martindale abrasion testing apparatus《纺织品耐摩损性马丁代尔试验法-第1部:马丁代尔耐摩损试验机》.pdf
  • CNS 15104-2007 Textiles - Determination of abrasion resistance of fabrics by the Martindale method - Part 2  Determination of specimen breakdown《纺织品耐摩损性马丁代尔试验法-第2部 试样耐摩损试验法》.pdf CNS 15104-2007 Textiles - Determination of abrasion resistance of fabrics by the Martindale method - Part 2 Determination of specimen breakdown《纺织品耐摩损性马丁代尔试验法-第2部 试样耐摩损试验法》.pdf
  • CNS 15105-2007 Textiles - Determination of abrasion resistance of fabrics by the Martindale method - Part 3  Determination of mass loss《纺织品耐摩损性马丁代尔试验法-第3部:质量减损试验法》.pdf CNS 15105-2007 Textiles - Determination of abrasion resistance of fabrics by the Martindale method - Part 3 Determination of mass loss《纺织品耐摩损性马丁代尔试验法-第3部:质量减损试验法》.pdf
  • CNS 15106-2007 Textiles - Determination of abrasion resistance of fabrics by the Martindale method - Part 4  Assessment of appearance change《纺织品耐摩损性马丁代尔试验法-第4部:外观变化评级法》.pdf CNS 15106-2007 Textiles - Determination of abrasion resistance of fabrics by the Martindale method - Part 4 Assessment of appearance change《纺织品耐摩损性马丁代尔试验法-第4部:外观变化评级法》.pdf
  • CNS 15107-2007 Textiles - Method for assessing appearance of apparel and other textile end products after domestic washing and drying《经家庭洗涤干燥后服饰及其它纺织制品之外观评估》.pdf CNS 15107-2007 Textiles - Method for assessing appearance of apparel and other textile end products after domestic washing and drying《经家庭洗涤干燥后服饰及其它纺织制品之外观评估》.pdf
  • CNS 15110-2007 Method of test for hydrocarbon types oxygenated compounds and benzene in spark ignition engine fuels by multi-dimensional gas chromatography《汽油碳氢化合物类型、含氧化物及苯含量测定法(多维.pdf CNS 15110-2007 Method of test for hydrocarbon types oxygenated compounds and benzene in spark ignition engine fuels by multi-dimensional gas chromatography《汽油碳氢化合物类型、含氧化物及苯含量测定法(多维.pdf
  • CNS 15111-2007 Methods of test for electrical conductivity and resistivity of water《水导电度及电阻率试验法》.pdf CNS 15111-2007 Methods of test for electrical conductivity and resistivity of water《水导电度及电阻率试验法》.pdf
  • CNS 15112-2007 Method of test for determination of olefin content of gasolines by supercritical-fluid chromatography《汽油烯烃含量测定法(超临界流体层析法)》.pdf CNS 15112-2007 Method of test for determination of olefin content of gasolines by supercritical-fluid chromatography《汽油烯烃含量测定法(超临界流体层析法)》.pdf
  • CNS 15113-2007 Solar photovoltaic energy systems - Terms and symbols《太阳光电能源系统:名词与符号》.pdf CNS 15113-2007 Solar photovoltaic energy systems - Terms and symbols《太阳光电能源系统:名词与符号》.pdf
  • 相关搜索

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

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