[计算机类试卷]国家二级C语言机试(操作题)模拟试卷673及答案与解析.doc

上传人:priceawful190 文档编号:498649 上传时间:2018-11-29 格式:DOC 页数:6 大小:30KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷673及答案与解析.doc_第1页
第1页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷673及答案与解析.doc_第2页
第2页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷673及答案与解析.doc_第3页
第3页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷673及答案与解析.doc_第4页
第4页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷673及答案与解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 673及答案与解析 一、程序填空题 1 函数 fun的功能是:根据所给的年、月、日,计算出该日是这一年的第几天,并作为函数值返回。其中函数 isleap用来判别某一年是否为闰年。 例如,若输入: 2008 5 1,则程序输出: 2008年 5月 1日是该年的第 122天。 请在程序的下画线处填入正确的内容,并把下画线删除,使程序得出正确的结果。 注意:不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h int isleap(int year) int leap; leap=(year 4=0&year 100 !=0|

2、year 400=0); return_1_; int fun(int year, int month, int day) int table13=0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31; int days=0, i; for(i=1; i month; i+) days=days+tablei; *found* days=days+_2_; if(isleap(year)&month 2) *found* days=days+_3_; return days; main() int year, month, day, days; p

3、rintf(“请输入年、月、日: “); scanf(“ d d d“, &year, &month, &day); days=fun(year, month, day); printf(“ d年 d月 d日是该年的第 d天 n“, year, month, day, days); 二 、程序修改题 2 下列给定程序中,函数 fun的功能是:计算函数 F(x, y, z)=(x+y) (x-y)+(z+y) (z-y)的值。其中 x和 y的值不相等, z和 y的值不相等。 例如,当 x的值为 9, y的值为 11, Z的值为 15时,函数值为 -3 50。 请改正程序中的错误,使它能得出正确的

4、结果。 注意:不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #include math h #include stdlib h *found* #define FU(m, n)(m n) float fun(float a, float b, float c) float value; value=FU(a+b, a-b)+FU(c+b, c-b); *found* Return(Value); main() float x, y, z, sum; printf(“Input x y z: “); scanf(“ f f f“, &x, &y, &z)

5、; printf(“x= f, y= f, z= f n“, x, y, z); if(x=y|y=z) printf(“Data error! n“); exit(0); sum=fun(x, y, z); printf(“The result is: 5 2f n“, sum); 三、程序设计题 3 编写函数 void fun(char*tt, int pp),统计在 tt所指的字符串中 a到 z26个小写字母各自出现的次数,并依次放在 pp所指的数组中。 例如,当输入字符串 “abcdefgabcdeab“后,程序的输出结果应该是: 3 3 3 2 2 1 1 0 0 0 0 0 0 0

6、 0 0 0 0 0 0 0 0 0 0 0 0 注意:请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio h #include string h void fun(char*tt, int p) main() char aa1000; int bb26, k; void NONO(); printf(“ nPlease enter a char string: “); scanf(“ s“, aa); fun(aa, bb); for(k=0; k 26; k+) printf(“ d“, bbk); p

7、rintf(“ n“); NONO(); void NONO() *本函数用于打开文件,输入测试数据, 调用 fun函数,输出数据,关闭文件。 * char aa1000; int bb26, k, i; FILE*rf, *wf; rf=fopen(“in dat“, “r“); wf=fopen(“out dat“, “w“); for(i=0; i 10; i+) fscanf(rf, “ s“, aa); fun(aa, bb); for(k=0; k 26; k+) fprintf(wf, “ d“, bbk); fprintf(wf, “ n“); felose(rf); fclo

8、se(wf); 国家二级 C语言机试(操作题)模拟试卷 673答案与解析 一、程序填空题 1 【正确答案】 (1)leap (2)day (3)1 【试题解析】 本题考查:对循环结构的理解和掌握。 填空 1: leap isleap()函数判断是否是闰年,由于初始化 2月为 28天,但是闰年是29,所以闰年要多 加 1天, isleap()应该返回 0或者 1, leap的表达式为逻辑运算,得到的结果刚好是 0或 1。 填空 2: day前面累加了平年月份的天数,还需要加上日的天数。 填空 3:如果是闰年并且累加月份大于 2月,需要多加 1天。 二、程序修改题 2 【正确答案】 (1)#def

9、ine FU(m, n)(m) (n) (2)return(value); 【试题解析】 本题考查: C语言宏定义;函数返回值。 本题考查 C语言的宏定义,其格式为: #de6ne标识符字符串,中间要用空格分开。在该题中,标识符为 Fu(m, n), 字符串为 (m n),由题干信息可知, m、 n均为表达式,且先进行表达式运算,再进行除法运算,因此此处应为 (m) (n)。 三、程序设计题 3 【正确答案】 void fun(char*tt, int pp) int i: for(i=0; i 26; i+) ppi=0; *初始化 pp数组各元素为 0* for(; *tt!= 0; tt+) if(*tt =a&*tt =z) pp*tt-a+; 【试题解析】 本题考查: for循环语句,注意循环变量取值范围以及 循环体语句作用;数组元素初始化和赋值操作; if语句条件表达式,需注意条件表达式的逻辑运算;字符串结束标识 0。 要求统计在 tt所指字符串中 a z共 26个小写母各自出现的次数,并依次放在 pp所指数组中。首先使用 for循环语句初始化 pp数组中分别用来统计 26个字母的个数,再使用循环判断语句对 tt所指字符串中的字符进行逐一比较操作,同时存入相对应的 pp数组中。

展开阅读全文
相关资源
猜你喜欢
  • ASTM A881 A881M-2005 Standard Specification for Steel Wire Deformed Stress-Relieved or Low-Relaxation for Prestressed Concrete Railroad Ties《预应力混凝土铁路轨枕用应力消除或应力松弛变形钢丝标准规范》.pdf ASTM A881 A881M-2005 Standard Specification for Steel Wire Deformed Stress-Relieved or Low-Relaxation for Prestressed Concrete Railroad Ties《预应力混凝土铁路轨枕用应力消除或应力松弛变形钢丝标准规范》.pdf
  • ASTM A881 A881M-2010 Standard Specification for Steel Wire Indented Low-Relaxation for Prestressed Concrete Railroad Ties《预应力混凝土铁路轨枕用应力消除或应力松弛变形钢丝的标准规格》.pdf ASTM A881 A881M-2010 Standard Specification for Steel Wire Indented Low-Relaxation for Prestressed Concrete Railroad Ties《预应力混凝土铁路轨枕用应力消除或应力松弛变形钢丝的标准规格》.pdf
  • ASTM A881 A881M-2015 Standard Specification for Steel Wire Indented Low-Relaxation for Prestressed Concrete Railroad Ties《用于预应力混凝土铁路轨枕的低松弛缩进钢丝的标准规格》.pdf ASTM A881 A881M-2015 Standard Specification for Steel Wire Indented Low-Relaxation for Prestressed Concrete Railroad Ties《用于预应力混凝土铁路轨枕的低松弛缩进钢丝的标准规格》.pdf
  • ASTM A881 A881M-2016 Standard Specification for Steel Wire Indented Low-Relaxation for Prestressed Concrete《用于预应力混凝土的低松弛缩进钢丝的标准规格》.pdf ASTM A881 A881M-2016 Standard Specification for Steel Wire Indented Low-Relaxation for Prestressed Concrete《用于预应力混凝土的低松弛缩进钢丝的标准规格》.pdf
  • ASTM A881 A881M-2016a Standard Specification for Steel Wire Indented Low-Relaxation for Prestressed Concrete《用于预应力混凝土的低松弛缩进钢丝的标准规格》.pdf ASTM A881 A881M-2016a Standard Specification for Steel Wire Indented Low-Relaxation for Prestressed Concrete《用于预应力混凝土的低松弛缩进钢丝的标准规格》.pdf
  • ASTM A882 A882M-2004a Standard Specification for Filled Epoxy-Coated Seven-Wire Prestressing Steel Strand.pdf ASTM A882 A882M-2004a Standard Specification for Filled Epoxy-Coated Seven-Wire Prestressing Steel Strand.pdf
  • ASTM A882 A882M-2004a(2010) Standard Specification for Filled Epoxy-Coated Seven-Wire Prestressing Steel Strand《涂环氧树脂的七股预应力钢丝绳的标准规范》.pdf ASTM A882 A882M-2004a(2010) Standard Specification for Filled Epoxy-Coated Seven-Wire Prestressing Steel Strand《涂环氧树脂的七股预应力钢丝绳的标准规范》.pdf
  • ASTM A884 A884M-2006 Standard Specification for Epoxy-Coated Steel Wire and Welded Wire Reinforcement《钢筋用涂环氧树脂的钢丝与焊接钢丝织网的技术规范》.pdf ASTM A884 A884M-2006 Standard Specification for Epoxy-Coated Steel Wire and Welded Wire Reinforcement《钢筋用涂环氧树脂的钢丝与焊接钢丝织网的技术规范》.pdf
  • ASTM A884 A884M-2012 Standard Specification for Epoxy-Coated Steel Wire and Welded Wire Reinforcement《焊接钢丝网配筋和环氧涂层钢丝用标准规格》.pdf ASTM A884 A884M-2012 Standard Specification for Epoxy-Coated Steel Wire and Welded Wire Reinforcement《焊接钢丝网配筋和环氧涂层钢丝用标准规格》.pdf
  • 相关搜索

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

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