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

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

1、二级 C 语言-229 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:输入两个正整数 num1 和 num2,求这两个数的最大公约数和最小公倍数。 例如,若输入的两个正整数为 12,4,则它们的最大公约数为 4,最小公倍数为 12。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h void main() int a,b,num1

2、num2,t; system(“CLS“); printf(“/nInput two numbers:/n“); scanf(“%d,%d“, if(num1num2) a=num2; b=num1; else a=num1; b=num2; while( 1) t= 2 a=b; b=t; printf(“greatest common divisor:%d/n“,a); printf(“least common multiple:%d/n“, 3); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中函数 proc 的功能是:取出长整型变量 s 中偶数位

3、上的数,依次构成一个新数放在 t 中。例如,当 s 中的数为 123456789 时,t 中的数为 2468。请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includestdio.h #includeconio.h /*found* void proc(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; void main() long

4、 s,t; system(“CLS“); printf(“/nPlease enter s:“); scanf(“%1d“, proc(s, printf(“The result is:%1d/n“,t); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写函数 proc(),其功能是:将 str 所指字符串中除下标为偶数、同时 ASCII 码值为奇数的字符外,其余的字符都删除,串中剩余字符所形成的一个新串放在 t 所指的数组中。例如,若 str 所指字符串中的内容为 ABCDEFG12345,其中字符 B 的 ASCII 码值为偶数,所在元素的下标为奇数,因此必须删

5、除;而字符 A 的 ASCII 码值为奇数,所在数组中的下标为偶数,因此不应当删除。依次类推,最后 t 所指的数组中的内容应是 ACEG。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的化括号中填入所写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h #includestring.h void proc(char*str,char t) void main() char str100,t100; system(“CLS“); printf(“/nPlease ent

6、er string str:“); scanf(“%s“,str); proc(str,t); printf(“/nThe result is:%s/n“,t); (分数:40.00)_二级 C 语言-229 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:输入两个正整数 num1 和 num2,求这两个数的最大公约数和最小公倍数。 例如,若输入的两个正整数为 12,4,则它们的最大公约数为 4,最小公倍数为 12。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在

7、 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h void main() int a,b,num1,num2,t; system(“CLS“); printf(“/nInput two numbers:/n“); scanf(“%d,%d“, if(num1num2) a=num2; b=num1; else a=num1; b=num2; while( 1) t= 2 a=b; b=t; printf(“greatest common divisor:%d/n“,a); printf(“least comm

8、on multiple:%d/n“, 3); (分数:30.00)解析:b!=0 a%b num1*num2/a解析 由程序可知,变量 b 中存放两个正整数中较小的那个数,while 循环求两个正整数的公约数。因此第一处填“b!=0”;第二处填“a%b”;第三处是求两个正整数最小公倍数的表达式,因此第三处填“num1*num2/a”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中函数 proc 的功能是:取出长整型变量 s 中偶数位上的数,依次构成一个新数放在 t 中。例如,当 s 中的数为 123456789 时,t 中的数为 2468。请修改程序中的错误,使它能得出正确的

9、结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includestdio.h #includeconio.h /*found* void proc(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; void main() long s,t; system(“CLS“); printf(“/nPlease enter s:“); scanf(“%1d“, proc(s, pr

10、intf(“The result is:%1d/n“,t); (分数:30.00)解析:错误:void proc(long s,long t) 正确:void proc(long s,long*t) 错误:while(s0) 正确:while(s0) 解析 从主函数中实参可知,形参的第二个变量是长整型的指针变量。因此“void proe(long s,long t)”应改为“void proc(long s,long*t)”;要从低位开始取出长整型变量 s 中偶数位上的数,每次变量 s 要除以 100,然后判断其是否大于 0 来决定是否要继续,因此“while(s0)”应改为“while(s0

11、)”。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 proc(),其功能是:将 str 所指字符串中除下标为偶数、同时 ASCII 码值为奇数的字符外,其余的字符都删除,串中剩余字符所形成的一个新串放在 t 所指的数组中。例如,若 str 所指字符串中的内容为 ABCDEFG12345,其中字符 B 的 ASCII 码值为偶数,所在元素的下标为奇数,因此必须删除;而字符 A 的 ASCII 码值为奇数,所在数组中的下标为偶数,因此不应当删除。依次类推,最后 t 所指的数组中的内容应是 ACEG。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在

12、函数 proc()的化括号中填入所写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h #includestring.h void proc(char*str,char t) void main() char str100,t100; system(“CLS“); printf(“/nPlease enter string str:“); scanf(“%s“,str); proc(str,t); printf(“/nThe result is:%s/n“,t); (分数:40.00)_正确答案:()解析:void proc(char*str,chart) int i,j=0; for(i=0;stri!=“/0“;i+)/从数组的第一个元素开始,到其最后一个 if(i%2=0 /如果成立,则把它放到 t 数组中 tj=“/0“;/字符串结束标志为“/0“ 解析 题目中要求将字符串 str 中下标为偶数、同时 ASCII 码值为奇数的字符放在数组 t 中。首先,需要检查字符串 str 中下标偶数的字符的 ASCII 码值是否为奇数,将符合要求的字符放在数组 t 中。最后,为新的字符串数组添加结束符。

展开阅读全文
相关资源
猜你喜欢
  • ASTM D5560-1995(2011) Standard Test Method for Determination of Neutral Fatty Matter Contained in Fats and Oils《测定脂肪和油中含中性脂肪物质的标准试验方法》.pdf ASTM D5560-1995(2011) Standard Test Method for Determination of Neutral Fatty Matter Contained in Fats and Oils《测定脂肪和油中含中性脂肪物质的标准试验方法》.pdf
  • ASTM D5560-1995(2018) Standard Test Method for Determination of Neutral Fatty Matter Contained in Fats and Oils.pdf ASTM D5560-1995(2018) Standard Test Method for Determination of Neutral Fatty Matter Contained in Fats and Oils.pdf
  • ASTM D5562-1995(2006) Standard Test Method for Determination of the Acidity as Free Fatty Acids Acid Number in the Presence of Ammonium or Triethanolamine Soaps《存在铵或三乙醇胺皂时酸度作为游离脂肪酸.pdf ASTM D5562-1995(2006) Standard Test Method for Determination of the Acidity as Free Fatty Acids Acid Number in the Presence of Ammonium or Triethanolamine Soaps《存在铵或三乙醇胺皂时酸度作为游离脂肪酸.pdf
  • ASTM D5562-1995(2011) Standard Test Method for Determination of the Acidity as Free Fatty Acids Acid Number in the Presence of Ammonium or Triethanolamine Soaps《存在铵或三乙醇胺皂时酸度作为游离脂肪酸.pdf ASTM D5562-1995(2011) Standard Test Method for Determination of the Acidity as Free Fatty Acids Acid Number in the Presence of Ammonium or Triethanolamine Soaps《存在铵或三乙醇胺皂时酸度作为游离脂肪酸.pdf
  • ASTM D5562-1995(2018) Standard Test Method for Determination of the Acidity as Free Fatty Acids Acid Number in the Presence of Ammonium or Triethanolamine Soaps.pdf ASTM D5562-1995(2018) Standard Test Method for Determination of the Acidity as Free Fatty Acids Acid Number in the Presence of Ammonium or Triethanolamine Soaps.pdf
  • ASTM D5564-1995(2006) Standard Test Method for Determination of the Total Ammonia Contained in Sulfonated or Sulfated Oils《硫酸化或磺酸化油中总氨含量测定的标准试验方法》.pdf ASTM D5564-1995(2006) Standard Test Method for Determination of the Total Ammonia Contained in Sulfonated or Sulfated Oils《硫酸化或磺酸化油中总氨含量测定的标准试验方法》.pdf
  • ASTM D5564-1995(2011) Standard Test Method for Determination of the Total Ammonia Contained in Sulfonated or Sulfated Oils《测定硫酸化或磺酸化油中总氨含量的标准试验方法》.pdf ASTM D5564-1995(2011) Standard Test Method for Determination of the Total Ammonia Contained in Sulfonated or Sulfated Oils《测定硫酸化或磺酸化油中总氨含量的标准试验方法》.pdf
  • ASTM D5564-1995(2018) Standard Test Method for Determination of the Total Ammonia Contained in Sulfonated or Sulfated Oils.pdf ASTM D5564-1995(2018) Standard Test Method for Determination of the Total Ammonia Contained in Sulfonated or Sulfated Oils.pdf
  • ASTM D5565-1995(2006) Standard Test Method for Determination of the Solidification Point of Fatty Acids Contained in Animal Marine and Vegetable Fats and Oils《测定动物、海洋动物和植物脂肪和油中脂肪酸凝.pdf ASTM D5565-1995(2006) Standard Test Method for Determination of the Solidification Point of Fatty Acids Contained in Animal Marine and Vegetable Fats and Oils《测定动物、海洋动物和植物脂肪和油中脂肪酸凝.pdf
  • 相关搜索

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

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