【计算机类职业资格】国家二级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函数执行完成就可以转到主函数中进行新字符串的输出了。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 3519-1994 Aerospace Series Steel FE-PL2105 Air Melted Hardened and Tempered Bar for Machining De Less Than or Equal to 150 mm 880 MPa Less Than or Equal to Rm Less Than .pdf AECMA PREN 3519-1994 Aerospace Series Steel FE-PL2105 Air Melted Hardened and Tempered Bar for Machining De Less Than or Equal to 150 mm 880 MPa Less Than or Equal to Rm Less Than .pdf
  • AECMA PREN 3520-1994 Aerospace Series Steel FE-PL2105 Air Melted Softened Forging Stock a or D Less Than or Equal to 300 mm Edition P 2《航空航天系列.钢FE-PL2105空气锻造和硬化和调和钢棒材和线材 a或D小于或等于30.pdf AECMA PREN 3520-1994 Aerospace Series Steel FE-PL2105 Air Melted Softened Forging Stock a or D Less Than or Equal to 300 mm Edition P 2《航空航天系列.钢FE-PL2105空气锻造和硬化和调和钢棒材和线材 a或D小于或等于30.pdf
  • AECMA PREN 3521-1998 Aerospace Series Steel FE-PL2106 (30CrNiMo8) Air Melted Hardened and Tempered Bar for Machining De Less Than or Equal to 150 mm 900 MPa Less Than or Equal to R.pdf AECMA PREN 3521-1998 Aerospace Series Steel FE-PL2106 (30CrNiMo8) Air Melted Hardened and Tempered Bar for Machining De Less Than or Equal to 150 mm 900 MPa Less Than or Equal to R.pdf
  • AECMA PREN 3522-1988 Aerospace Series Steel FE-PL79 Softened Reference Heat Treatment Carburized Hardened and Tempered Forging Stock De Less Than or Equal to 200 mm Issue P 1《航空航天系.pdf AECMA PREN 3522-1988 Aerospace Series Steel FE-PL79 Softened Reference Heat Treatment Carburized Hardened and Tempered Forging Stock De Less Than or Equal to 200 mm Issue P 1《航空航天系.pdf
  • AECMA PREN 3523-1999 Aerospace Series Steel FE-PL1505 (15CrMoV6) Air Melted Hardened and Tempered Bar for Machining De Less Than or Equal to 100 mm 1 080 MPa Less Than or Equal to .pdf AECMA PREN 3523-1999 Aerospace Series Steel FE-PL1505 (15CrMoV6) Air Melted Hardened and Tempered Bar for Machining De Less Than or Equal to 100 mm 1 080 MPa Less Than or Equal to .pdf
  • AECMA PREN 3524-1999 Aerospace Series Steel FE-PL1505 (15CrMoV6) Air Melted Hardened and Tempered Sheet and Strip 2 mm Less Than or Equal to a Less Than or Equal to 6 mm 1 080 MPa .pdf AECMA PREN 3524-1999 Aerospace Series Steel FE-PL1505 (15CrMoV6) Air Melted Hardened and Tempered Sheet and Strip 2 mm Less Than or Equal to a Less Than or Equal to 6 mm 1 080 MPa .pdf
  • AECMA PREN 3525-1999 Aerospace Series Steel FE-PL1505 (15CrMoV6) Air Melted Hardened and Tempered Plate 6 mm Less Than or Equal to a Less Than or Equal to 20 mm 1 080 MPa Less Than航.pdf AECMA PREN 3525-1999 Aerospace Series Steel FE-PL1505 (15CrMoV6) Air Melted Hardened and Tempered Plate 6 mm Less Than or Equal to a Less Than or Equal to 20 mm 1 080 MPa Less Than航.pdf
  • AECMA PREN 3526-1999 Aerospace Series Steel FE-PL1505 (15CrMoV6) Air Melted Hardened and Tempered Sheet and Strip 0 5 mm Less Than or Equal to a Less Than or Equal to 6 mm 980 MPa t.pdf AECMA PREN 3526-1999 Aerospace Series Steel FE-PL1505 (15CrMoV6) Air Melted Hardened and Tempered Sheet and Strip 0 5 mm Less Than or Equal to a Less Than or Equal to 6 mm 980 MPa t.pdf
  • AECMA PREN 3527-1998 Aerospace Series Steel FE-PL1504 (33CrMoV12) Air Melted Softened Forging Stock a or D Less Than or Equal to 300 mm Edition P2《航空航天系列.钢 FE-PL1504(33CrMoV12) 空气熔.pdf AECMA PREN 3527-1998 Aerospace Series Steel FE-PL1504 (33CrMoV12) Air Melted Softened Forging Stock a or D Less Than or Equal to 300 mm Edition P2《航空航天系列.钢 FE-PL1504(33CrMoV12) 空气熔.pdf
  • 相关搜索

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

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