【计算机类职业资格】全国计算机等级考试二级C语言上机题库试卷六2013年3月及答案解析.doc

上传人:inwarn120 文档编号:1329655 上传时间:2019-10-17 格式:DOC 页数:2 大小:30KB
下载 相关 举报
【计算机类职业资格】全国计算机等级考试二级C语言上机题库试卷六2013年3月及答案解析.doc_第1页
第1页 / 共2页
【计算机类职业资格】全国计算机等级考试二级C语言上机题库试卷六2013年3月及答案解析.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

1、全国计算机等级考试二级 C语言上机题库试卷六 2013年 3月及答案解析(总分:3.00,做题时间:90 分钟)1.给定程序中,函数 fun的功能是根据形参 i的值返回某个函数的值。当调用正确时, 程序输出: x1=5.000000, x2=3.000000, x1*x1+x1*x2=40.000000 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include double f1(double x) return x*x; double f2(doubl

2、e x, double y) return x*y; _1_ fun(int i, double x, double y) if (i=1) return _2_(x); else return _3_(x, y); main() double x1=5, x2=3, r; r = fun(1, x1, x2); r += fun(2, x1, x2); printf(“/nx1=%f, x2=%f, x1*x1+x1*x2=%f/n/n“,x1, x2, r); (分数:1.00)_2.给定程序 MODI1.C中函数 fun的功能是: 比较两个字符串,将长的那个字符串的首地址作为函数值返回。

3、请改正函数 fun中指定部位的错误, 使它能得出正确的结果。 注意: 不要改动 main函数, 不得增行或删行, 也不得更改程序的结构! 给定源程序: #include char fun(char *s, char *t) int sl=0,tl=0; char *ss, *tt; ss=s; tt=t; while(*ss) sl+; (*ss)+; while(*tt) tl+; (*tt)+; if(tlsl) return t; else return s; main() char a80,b80,*p,*q; int i; printf(“/nEnter a string : “);

4、 gets(a); printf(“/nEnter a string again : “); gets(b); printf(“/nThe longer is :/n/n/“%s/“/n“,fun(a,b); (分数:1.00)_3.请编写函数 fun,函数的功能是: 移动字符串中的内容,移动的规则如下: 把第 1到第 m个字符,平移到字符串的最后, 把第 m+1到最后的字符移到字符串的前部。 例如, 字符串中原有的内容为: ABCDEFGHIJK, m的值为 3, 则移动后, 字符串中的内容应该是: DEFGHIJKABC。 注意:部分源程序在文件 PROG1.C中。 请勿改动主函数 mai

5、n和其它函数中的任何内容, 仅在函数 fun的花括号中填入你编写的若干语句。 给定源程序: #include #include #define N 80 void fun1(char *w) /* 本函数的功能是将字符串中字符循环左移一个位置 */ int i; char t; t=w0; for(i=0;i_全国计算机等级考试二级 C语言上机题库试卷六 2013年 3月答案解析(总分:3.00,做题时间:90 分钟)1.给定程序中,函数 fun的功能是根据形参 i的值返回某个函数的值。当调用正确时, 程序输出: x1=5.000000, x2=3.000000, x1*x1+x1*x2=40

6、000000 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include double f1(double x) return x*x; double f2(double x, double y) return x*y; _1_ fun(int i, double x, double y) if (i=1) return _2_(x); else return _3_(x, y); main() double x1=5, x2=3, r; r = fun

7、1, x1, x2); r += fun(2, x1, x2); printf(“/nx1=%f, x2=%f, x1*x1+x1*x2=%f/n/n“,x1, x2, r); (分数:1.00)_正确答案:()解析:本题是根据给定的公式来计算函数的值。 第一处:程序中使用双精度 double类型进行计算,所以函数的返回值类型也为 double,所以应填:double。 第二处:当 i等于 1时,则返回 f1函数的值,所以应填:f1。 第三处:如果 i不等于 1,则返回 f2函数的值,所以应填:f2。2.给定程序 MODI1.C中函数 fun的功能是: 比较两个字符串,将长的那个字符串的首地

8、址作为函数值返回。请改正函数 fun中指定部位的错误, 使它能得出正确的结果。 注意: 不要改动 main函数, 不得增行或删行, 也不得更改程序的结构! 给定源程序: #include char fun(char *s, char *t) int sl=0,tl=0; char *ss, *tt; ss=s; tt=t; while(*ss) sl+; (*ss)+; while(*tt) tl+; (*tt)+; if(tlsl) return t; else return s; main() char a80,b80,*p,*q; int i; printf(“/nEnter a str

9、ing : “); gets(a); printf(“/nEnter a string again : “); gets(b); printf(“/nThe longer is :/n/n/“%s/“/n“,fun(a,b); (分数:1.00)_正确答案:()解析:第一处: 试题要求返回字符串的首地址,所以应改为:char *fun(char *s,char *t) 第二处: 取字符串指针 ss的下一个位置,所以应改为:ss+;。 第三处:取字符串指针 tt的下一个位置,所以应改为:tt+;。3.请编写函数 fun,函数的功能是: 移动字符串中的内容,移动的规则如下: 把第 1到第 m个字符

10、平移到字符串的最后, 把第 m+1到最后的字符移到字符串的前部。 例如, 字符串中原有的内容为: ABCDEFGHIJK, m的值为 3, 则移动后, 字符串中的内容应该是: DEFGHIJKABC。 注意:部分源程序在文件 PROG1.C中。 请勿改动主函数 main和其它函数中的任何内容, 仅在函数 fun的花括号中填入你编写的若干语句。 给定源程序: #include #include #define N 80 void fun1(char *w) /* 本函数的功能是将字符串中字符循环左移一个位置 */ int i; char t; t=w0; for(i=0;i_正确答案:(void fun1(char *w) /* 本函数的功能是将字符串中字符循环左移一个位置 */ int i; char t; t=w0; for(i=0;i m ; i+) fun1(w); )解析:本题是考察字符串的操作。 1. 由于函数 fun1是将字符串中字符循环左移一个位置,并通过实参w返回循环左移一个位置的字符串。 2. 利用循环 for语句来操作多少个字符(m)需要循环左移。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO IEC 10026-6-1995 Information technology - Open systems interconnection - Distributed transaction processing - Unstructured data transfer《信息技术 开放式系统互连 分布式执行处理 非结构数据传.pdf BS ISO IEC 10026-6-1995 Information technology - Open systems interconnection - Distributed transaction processing - Unstructured data transfer《信息技术 开放式系统互连 分布式执行处理 非结构数据传.pdf
  • BS ISO IEC 10030-1995 Information technology - Telecommunications and information exchange between systems - End System Routeing Information Exchange protocol for use in c.pdf BS ISO IEC 10030-1995 Information technology - Telecommunications and information exchange between systems - End System Routeing Information Exchange protocol for use in c.pdf
  • BS ISO IEC 10040-1993 Information technology - Open systems interconnection - Systems management overview《信息技术 开放式系统互连 系统管理综述》.pdf BS ISO IEC 10040-1993 Information technology - Open systems interconnection - Systems management overview《信息技术 开放式系统互连 系统管理综述》.pdf
  • BS ISO IEC 10089-1991 Information technology - 130 mm rewritable optical disk cartridge for information interchange《信息技术 信息交换用130mm可重写光盘盒》.pdf BS ISO IEC 10089-1991 Information technology - 130 mm rewritable optical disk cartridge for information interchange《信息技术 信息交换用130mm可重写光盘盒》.pdf
  • BS ISO IEC 10090-1993 Information technology - 90 mm optical disk cartridges rewritable and read only for data interchange《信息技术 数据交换用可重写和只读90mm盒式光盘》.pdf BS ISO IEC 10090-1993 Information technology - 90 mm optical disk cartridges rewritable and read only for data interchange《信息技术 数据交换用可重写和只读90mm盒式光盘》.pdf
  • BS ISO IEC 10116-2017 Information technology Security techniques Modes of operation for an n-bit block cipher《信息技术 安全技术 n位块密码算法的操作方式》.pdf BS ISO IEC 10116-2017 Information technology Security techniques Modes of operation for an n-bit block cipher《信息技术 安全技术 n位块密码算法的操作方式》.pdf
  • BS ISO IEC 10118-1-2016 Information technology Security techniques Hash-functions General《信息技术 保密技术 信息函数 第1部分 综述》.pdf BS ISO IEC 10118-1-2016 Information technology Security techniques Hash-functions General《信息技术 保密技术 信息函数 第1部分 综述》.pdf
  • BS ISO IEC 10118-2-2010 Information technology Security techniques Hash-functions Hash-functions using an n-bit block cipher《信息技术 保密技术 散列函数 使用一个N-位数据块密码算法的散列函数》.pdf BS ISO IEC 10118-2-2010 Information technology Security techniques Hash-functions Hash-functions using an n-bit block cipher《信息技术 保密技术 散列函数 使用一个N-位数据块密码算法的散列函数》.pdf
  • BS ISO IEC 10177-1993 Information technology - Telecommunications and information exchange between systems - Provision of the connection-mode Network internal layer servic.pdf BS ISO IEC 10177-1993 Information technology - Telecommunications and information exchange between systems - Provision of the connection-mode Network internal layer servic.pdf
  • 相关搜索
    资源标签

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

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