【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷394及答案解析.doc

上传人:medalangle361 文档编号:1332208 上传时间:2019-10-17 格式:DOC 页数:3 大小:36KB
下载 相关 举报
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷394及答案解析.doc_第1页
第1页 / 共3页
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷394及答案解析.doc_第2页
第2页 / 共3页
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷394及答案解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 394及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.函数 fun的功能是:根据所给的年、月、日,计算出该日是这一年的第几天,并作为函数值返回。其中函数 isleap用来判别某一年是否为闰年。 例如,若输入:2008 5 1,则程序输出:2008 年 5月 1日是该年的第 122天。 请在程序的下划线处填入正确的内容,并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1C 中。 不得增行或删行,也不得更改程序的结构!1 #includestdioh2 int isleap

2、int year)3 int leap;4 leap=(year4=0 iy; i+)7 t=t* x;8 *p=t;9 *found*10 t=t1000;11 return t;12 13 main()14 long t,r; int x,y;15 printf(nTnput x and y: );scanf(1d1d,19 20 void NONO()21 *本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*22 FILE *in,*out;23 int i ; char s81;24 in=fopen(indat,r);25 out=fopen(outdat,w);26

3、for(i=0;i10;i+) 27 fscanf(in,s,s);28 fun(s);29 fprintf(out,sn,s);30 31 fclose(in);32 fclose(out);33 (分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 394答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.函数 fun的功能是:根据所给的年、月、日,计算出该日是这一年的第几天,并作为函数值返回。其中函数 isleap用来判别某一年是否为闰年。 例如,若输入:2008 5 1,则程序输出:2008 年 5月 1日是该年的第 122天。 请在程

4、序的下划线处填入正确的内容,并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1C 中。 不得增行或删行,也不得更改程序的结构!1 #includestdioh2 int isleap(int year)3 int leap;4 leap=(year4=0 iy; i+)7 t=t* x;8 *p=t;9 *found*10 t=t1000;11 return t;12 13 main()14 long t,r; int x,y;15 printf(nTnput x and y: );scanf(1d1d,iy;i+)”改为“for(i=1;i=y;i+)”。

5、2)题目中要求截取前面求得结果的低三位,因此,第二个标识下“t=t1000;”应该改为“t=t1000;”。三、程序设计题(总题数:1,分数:2.00)3.假定输入的字符串中只包含字母和*号。请编写函数 fun,它的功能是:除了字符串前导的*号之外,将串中其它“*”号全部删除。在编写函数时,不得使用 C语言提供的字符串函数。函数 fun中给出的语句仅供参考。 例如, 字符串中的内容为:*A*BC*DEF*G*,删除后字符串中的内容应当是:*ABCDEFG。 注意:部分源程序在文件 PROG1C 文件中。 请勿改动主函数 main和其它函数中的任何内容,仅在函数 fun的花括号中填入你编写的若

6、干语句。1 #includestdio.h2 void fun(char*a)3 4 *以下代码仅供参考*5 int i=0,k;6 while(ai=*)i+;7 k=i;8 while(ai!=0)*以下程序段实现非*字符前移*9 10 11 ak=0;12 13 main()14 char s81;void NONO();15 printf(Enter a string:n);gets(s);16 fun(s);17 printf(The string after deleted:n);puts(s);18 NONO();19 20 void NONO()21 *本函数用于打开文件,输入

7、数据,调用函数,输出数据,关闭文件。*22 FILE *in,*out;23 int i ; char s81;24 in=fopen(indat,r);25 out=fopen(outdat,w);26 for(i=0;i10;i+) 27 fscanf(in,s,s);28 fun(s);29 fprintf(out,sn,s);30 31 fclose(in);32 fclose(out);33 (分数:2.00)_正确答案:(正确答案:2 void fun( char *a ) 3 int i=0,k; 4 while(ai=*)i+; 5 k=i; 6 while(ai!=0) 7

8、if(ai!=*) ak+=ai; 8 i+; 9 10 ak=0; 11 )解析:解析:本题主函数中需要输入一个字符串,然后进入 fun函数处理字符串,在 fun函数中,就要实现题目要求我们写出的功能了。首先是判断字符串的开始是否为“*”,这里就用到 while函数(这里因为有步骤的区别,所以这里用 while比用 if好),判断开始的字符是否为“*”,见程序第 56 行,这里需要顺次进行,因为开始无论有多少个“*”都不用删除,当出现字母时,就开始下一步了,因为已经出现了字母,所以后面出现的“*”一律删除,而字母时不用管的,所以这里就又需要 if条件语句来判断是否为“*”然后赋值为空,见程序第 912 行,当程序进行到字符为空时代表字符串结束,程序就终止,这里就要用到 while条件语句进行终止判断,见程序第 7行。这样循环进行就能保留字符串前面的“*”并且删除后面出现的所有“*”了,然后 fun函数执行完成就可以转到主函数中进行新字符串的输出了。

展开阅读全文
相关资源
猜你喜欢
  • BS 476-23-1987 Fire tests on building materials and structures - Methods for determination of the contribution of components to the fire resistance of a structure《建筑材料和结构的燃烧试验 第23部.pdf BS 476-23-1987 Fire tests on building materials and structures - Methods for determination of the contribution of components to the fire resistance of a structure《建筑材料和结构的燃烧试验 第23部.pdf
  • BS 476-24-1987 Fire tests on building materials and structures - Method for determination of the fire resistance of ventilation ducts《建筑材料和结构的燃烧试验 第24部分 通风管道耐火性的测定方法》.pdf BS 476-24-1987 Fire tests on building materials and structures - Method for determination of the fire resistance of ventilation ducts《建筑材料和结构的燃烧试验 第24部分 通风管道耐火性的测定方法》.pdf
  • BS 476-3-2004 Fire tests on building nmaterials and nstructures — nPart 3 Classification and method of test nfor external fire exposure to roofs《建筑材料和构件的燃烧试验 外部屋顶着火试验方法和分类》.pdf BS 476-3-2004 Fire tests on building nmaterials and nstructures — nPart 3 Classification and method of test nfor external fire exposure to roofs《建筑材料和构件的燃烧试验 外部屋顶着火试验方法和分类》.pdf
  • BS 476-31 1-1983 Fire tests on building materials and structures - Methods for measuring smoke penetration through doorsets and shutter assemblies - Method of measurement under amb.pdf BS 476-31 1-1983 Fire tests on building materials and structures - Methods for measuring smoke penetration through doorsets and shutter assemblies - Method of measurement under amb.pdf
  • BS 476-32-1989 Fire tests on building materials and structures - Guide to full scale fire tests within buildings《建筑材料和结构的燃烧试验 第32部分 建筑物内实物尺寸燃烧试验指南》.pdf BS 476-32-1989 Fire tests on building materials and structures - Guide to full scale fire tests within buildings《建筑材料和结构的燃烧试验 第32部分 建筑物内实物尺寸燃烧试验指南》.pdf
  • BS 476-33-1993 Fire tests on building materials and structures - Full-scale room test for surface products《建筑材料和结构的燃烧试验 表面产品的实物尺寸的室内试验》.pdf BS 476-33-1993 Fire tests on building materials and structures - Full-scale room test for surface products《建筑材料和结构的燃烧试验 表面产品的实物尺寸的室内试验》.pdf
  • BS 476-4-1970 Fire tests on building materials and structures - Non-combustibility test for materials《建筑材料和结构的燃烧试验 材料的不可燃性试验》.pdf BS 476-4-1970 Fire tests on building materials and structures - Non-combustibility test for materials《建筑材料和结构的燃烧试验 材料的不可燃性试验》.pdf
  • BS 476-7-1997 Fire tests on building materials and structures - Method of test to determine the classification of the surface spread of flame of products《建筑材料和构件燃烧试验 第7部分 测定制品火焰表面蔓.pdf BS 476-7-1997 Fire tests on building materials and structures - Method of test to determine the classification of the surface spread of flame of products《建筑材料和构件燃烧试验 第7部分 测定制品火焰表面蔓.pdf
  • BS 4761-1971 Specification for sprayed unfused metal coatings for engineering purposes《工程用喷镀的未熔金属度层规范》.pdf BS 4761-1971 Specification for sprayed unfused metal coatings for engineering purposes《工程用喷镀的未熔金属度层规范》.pdf
  • 相关搜索

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

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