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

上传人:jobexamine331 文档编号:1325071 上传时间:2019-10-17 格式:DOC 页数:5 大小:31.50KB
下载 相关 举报
【计算机类职业资格】二级C语言-243及答案解析.doc_第1页
第1页 / 共5页
【计算机类职业资格】二级C语言-243及答案解析.doc_第2页
第2页 / 共5页
【计算机类职业资格】二级C语言-243及答案解析.doc_第3页
第3页 / 共5页
【计算机类职业资格】二级C语言-243及答案解析.doc_第4页
第4页 / 共5页
【计算机类职业资格】二级C语言-243及答案解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 C 语言-243 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是找出 100 至 x(x999)之间各位上的数字之和为 15 的所有整数,然后输出;符合条件的整数个数作为函数值返回。 例如,当 n 值为 500 时,各位数字之和为 15 的整数有:159、168、177、186、195、249、258、267、276、285、294、339、348、357、366、375、384、393、429、438、447、456、465、474、483、492。共有 26 个。 请在程序的下划线处填入正确的

2、内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! 给定源程序如下。 #includestdio.h int fun(int x) int n,s1,s2,s3,t; /*found*/ n= 1; t=100; /*found*/ while(t= 2) s1=t%10;s2=(t/10)%10;s3=t/100; if(s1+s2+s3=15) printf(“:=:%d“:=:,t); n+; /*found*/ 3; return n; main() int x=-1; while(x999|x0

3、) printf(“Please input(0x=999):“); scanf(“%d“t, prinrf(“/nThe result is:%d/n“,fun(x); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.给定程序 MODI1.C 中函数 fun 的功能是先将 s 所指字符串中的字符按逆序存放到 t 所指字符串中,然后把 s 所指串中的字符按正序连接到 t 所指串的后面。 例如:当 s 所指的字符串为“ABCDE”时,则 t 所指的字符串应为“EDCBAABCDE”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行

4、,也不得更改程序的结构! 给定源程序如下。 #includestdio.h #includestring.h void fun(char*s,char*t) /*found*/ int i; i=0; s1=strlen(s); for(;is1;i+) /*found*/ ti=ss-i; for(i=0;is1;i+) ts1+i=si; t2*s1=“/0“; main() char s100,t100; printf(“/nPlease enter string s:“);scanf(“%s“,s); fun(s,t); printf(“The resuh is:%s/n“,t); (

5、分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.函数 fun 的功能是将 a、b 中的两个两位正整数合并形成一个新的整数放在 c 中。合并的方式是将 a 中的十位和个位数依次放在变量 c 的百位和个位上,b 中的十位和个位数依次放在变量 c 的千位和十位上。 例如,当 a=45,b=12 时,调用该函数后,c=1425。 注意:部分源程序存在文件 PROG1.C 中。数据文件 IN.DAT 中的数据不得修改。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入编写的若干语句。 给定源程序如下。 #includestdio.h void fun

6、(int a,int b,long*c) main()/*主函数*/ int a,b;long c; printf(“Input a b:“); scanf(“%d%d“, fun(a,b, printf(“The result is:%ld/n“,c); (分数:40.00)_二级 C 语言-243 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是找出 100 至 x(x999)之间各位上的数字之和为 15 的所有整数,然后输出;符合条件的整数个数作为函数值返回。 例如,当 n 值为 500 时,各位数字

7、之和为 15 的整数有:159、168、177、186、195、249、258、267、276、285、294、339、348、357、366、375、384、393、429、438、447、456、465、474、483、492。共有 26 个。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! 给定源程序如下。 #includestdio.h int fun(int x) int n,s1,s2,s3,t; /*found*/ n= 1; t=100; /*found*/

8、 while(t= 2) s1=t%10;s2=(t/10)%10;s3=t/100; if(s1+s2+s3=15) printf(“:=:%d“:=:,t); n+; /*found*/ 3; return n; main() int x=-1; while(x999|x0) printf(“Please input(0x=999):“); scanf(“%d“t, prinrf(“/nThe result is:%d/n“,fun(x); (分数:30.00)解析:0 x t+ 解析 填空 1:变量 n 用于存放符合条件的整数的个数,应赋初值为 0。 填空 2:根据题目要求,确定循环变量

9、 t 的取值范围 t=x。 填空 3:循环变量 t 自增 1 操作。二、程序改错题(总题数:1,分数:30.00)2.给定程序 MODI1.C 中函数 fun 的功能是先将 s 所指字符串中的字符按逆序存放到 t 所指字符串中,然后把 s 所指串中的字符按正序连接到 t 所指串的后面。 例如:当 s 所指的字符串为“ABCDE”时,则 t 所指的字符串应为“EDCBAABCDE”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序如下。 #includestdio.h #includestring.h void fu

10、n(char*s,char*t) /*found*/ int i; i=0; s1=strlen(s); for(;is1;i+) /*found*/ ti=ss-i; for(i=0;is1;i+) ts1+i=si; t2*s1=“/0“; main() char s100,t100; printf(“/nPlease enter string s:“);scanf(“%s“,s); fun(s,t); printf(“The resuh is:%s/n“,t); (分数:30.00)解析:int i,s1; ti=ss1-i-1; 解析 变量 s1 没有定义。 该循环实现将 s 串中的字

11、符逆序存入 t 串中,ti对应 s 串中的 ss1-i-1。三、程序设计题(总题数:1,分数:40.00)3.函数 fun 的功能是将 a、b 中的两个两位正整数合并形成一个新的整数放在 c 中。合并的方式是将 a 中的十位和个位数依次放在变量 c 的百位和个位上,b 中的十位和个位数依次放在变量 c 的千位和十位上。 例如,当 a=45,b=12 时,调用该函数后,c=1425。 注意:部分源程序存在文件 PROG1.C 中。数据文件 IN.DAT 中的数据不得修改。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入编写的若干语句。 给定源程序如下。 #in

12、cludestdio.h void fun(int a,int b,long*c) main()/*主函数*/ int a,b;long c; printf(“Input a b:“); scanf(“%d%d“, fun(a,b, printf(“The result is:%ld/n“,c); (分数:40.00)_正确答案:()解析:void fun(int a,int b,long*c) *c=a%10+(b%10)*10+(a/10)*100+(b/10)*1000; 解析 本题的主要问题是如何取出 a 和 b 的个位数和十位数,取出后如何表示成 c 中相应的位数。由于 a 和 b 都是只有两位的整数,所以分别对它们除以 10 可得到它们的十位数,分别用 10 对它们求余可得到它们的个位数。得到后对应乘以 1000、100、10、1 就可得到 c 的千位数、百位数、十位数和个位数。注意:使用 c 时要进行指针运算。

展开阅读全文
相关资源
猜你喜欢
  • NY T 3108-2017 Technical code of practice for the prevention and reduction of zearalenone contamination in wheat《小麦中玉米赤霉烯酮类毒素预防和减控技术规程》.pdf NY T 3108-2017 Technical code of practice for the prevention and reduction of zearalenone contamination in wheat《小麦中玉米赤霉烯酮类毒素预防和减控技术规程》.pdf
  • NY T 3109-2017 Determination of capsaicinoid in vegetable oil products Immunoassay《植物油脂中辣椒素的测定 免疫分析法》.pdf NY T 3109-2017 Determination of capsaicinoid in vegetable oil products Immunoassay《植物油脂中辣椒素的测定 免疫分析法》.pdf
  • NY T 3110-2017 Determination of fattyacidprofilesin vegetable oilseeds Gas chromatography mass spectrometry《植物油料中全谱脂肪酸的测定 气相色谱质谱法》.pdf NY T 3110-2017 Determination of fattyacidprofilesin vegetable oilseeds Gas chromatography mass spectrometry《植物油料中全谱脂肪酸的测定 气相色谱质谱法》.pdf
  • NY T 3111-2017 Determination of sterols in vegetable oils Gas chromatography mass spectrometry《植物油中甾醇含量的测定 气相色谱质谱法》.pdf NY T 3111-2017 Determination of sterols in vegetable oils Gas chromatography mass spectrometry《植物油中甾醇含量的测定 气相色谱质谱法》.pdf
  • NY T 3112-2017 Determination of isoflavones in vegetable oils Liquid chromatography tandem mass spectrometry《植物油中异黄酮的测定 液相色谱串联质谱法》.pdf NY T 3112-2017 Determination of isoflavones in vegetable oils Liquid chromatography tandem mass spectrometry《植物油中异黄酮的测定 液相色谱串联质谱法》.pdf
  • NY T 3113-2017 Determination of six phenolic compounds in vegetable oils Liquid chromatography tandem mass spectrometry《植物油中香草酸等6种多酚的测定 液相色谱串联质谱法》.pdf NY T 3113-2017 Determination of six phenolic compounds in vegetable oils Liquid chromatography tandem mass spectrometry《植物油中香草酸等6种多酚的测定 液相色谱串联质谱法》.pdf
  • NY T 3114 1-2017 Technical specification for evaluation of soybean for resistance to pests Part 1 Technical specification for evaluation of soybean for resistan.pdf NY T 3114 1-2017 Technical specification for evaluation of soybean for resistance to pests Part 1 Technical specification for evaluation of soybean for resistan.pdf
  • NY T 3114 2-2017 Technical specification for evaluation of soybean for resistance to pests Part 2 Technical specification for evaluation of soybean for resistan.pdf NY T 3114 2-2017 Technical specification for evaluation of soybean for resistance to pests Part 2 Technical specification for evaluation of soybean for resistan.pdf
  • NY T 3114 3-2017 Technical specification for evaluation of soybean for resistance to pests Part 3 Technical specification for evaluation of soybean for resistan.pdf NY T 3114 3-2017 Technical specification for evaluation of soybean for resistance to pests Part 3 Technical specification for evaluation of soybean for resistan.pdf
  • 相关搜索

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

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