[计算机类试卷]国家二级C语言程序设计机试(程序修改题)模拟试卷5及答案与解析.doc

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

1、国家二级 C语言程序设计机试(程序修改题)模拟试卷 5及答案与解析 一、程序修改题 1 下列给定程序中,函数 fun的功能是:计算整数 n的阶乘。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include #include double fun(int n) double result: 1 0; while(n1&n #include int fun(int a, int b, int c) if(a+bc&b+ca &a+cb) if(a=b& b=c) *found* return 1; else i

2、f(a=bb=c a=c) return 2; *found* else return 3; else retum 0; void main() int a, b, c, shape; prinff(“ nInput a, b, c: ”); seanf(“ d d d”, &a, &b, c); prinff(“ ha= d, b= d, c= d n”, a, b, c); shape=fun(a, b, c); printf(“ nThe shape: d n”, shape); 3 下 列给定的程序中,函数 fun的功能是:计算并输出 k以内最大的 10个能被 13或 17整除的自然数

3、之和。 k的值由主函数传入,若 k的值为 500,则函数的值为4622。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #nelude #include #include int fun(int k) int m=0, mc=0, j; while(k=2)&(me #include void fun(char*a, char*b, char*c) int i, j; char ch; i=0; j=strlen(b)一 1; *found* while(ij) ch=bi; bi=bj; bj=eh; 1+;

4、一一; while(*a*b) *found* If(*a) *c= *a; c+; a+; if($b) * c=*b; c+; b+; *c=0: main() char sl100, s2100, t200; prinff(“ nEnter sl string: ”); scanf(“ S”, s1); prinff(“ nEnter s2 string: ”); scanf(“ s”, s2); fun(s1, s2, t); printf(“ nThe result is: s n”, t); 国家二级 C语言程序设计机试(程序修改题)模拟试卷 5答案与解析 一、程序修改题 1 【正

5、确答案】 (1)result*=n一一; (2)retum result; 【试题解析】 本题考查:复合赋值运算;通过 return语句完成函数值的返回。 该题采用循环语句计算 n的阶乘。当 n大于 1且小于 170时,令 result与 n相乘,同时 n自动减 1,循环至 n=2(n=1时无须相乘 )。最后将阶乘的积 result返回给主函数。 2 【正确答案】 (1)return 3; (2)return 1; 【试题解析】 (1)变量 a、 b、 c分别表示三条边,当三边相等 (a=b &b=c)时,返回 3。 (2)在能构成三角形的前提下,如果 不能构成等边三角形或等腰三角形,则返回1

6、。 3 【正确答案】 (1)if(k 13=0)(k 17=0) (2)return m; 【试题解析】 (1)c语言中, x能被 y整除的表示方法是 x y=0,而不是题目中所表示的 x y=0。所以, if(k 13=0)(k 17=0)修改后的结果应该是答案所示信息。 (2)程序中缺少程序完整所需的 “”,此类信息在做题时一定要注意,可以在做题前先运行一下程序,这样明显的错误一般都会有错误信息显示出来。比如丢失 “”的错误信息是 “Compouncl statement missingin flruction fun”。 说明:做题之前先运行一下程序,如果有书写错误,系统会提示,这样可以简化题目。 4 【正确答案】 (1)while(ij) (2)if(*a) 【试题解析】 (1)由 i和 j定义的初始值可知,此处应该判断 i是否小于 j,所以应改为 while(ij)。 (2)此处将 if错写成 If,这个错误比较简单,但往往不容易发现。

展开阅读全文
相关资源
猜你喜欢
  • ANSI T1.602-1996 Integrated Services Digital Network (ISDN) - Data-Link Layer Signaling Specification for Application at the User-Network Interface《电信.综合服务数字网络(ISDN).用户网络接口的数据链路层信令.pdf ANSI T1.602-1996 Integrated Services Digital Network (ISDN) - Data-Link Layer Signaling Specification for Application at the User-Network Interface《电信.综合服务数字网络(ISDN).用户网络接口的数据链路层信令.pdf
  • ANSI T1.605-1991 Integrated Services Digital Network (ISDN) - Basic Access Interface for S and T Reference Points (Layer 1 Specification)《综合服务数字网络(ISDN).S和T基准点的基本访问接口(第一层规范)》.pdf ANSI T1.605-1991 Integrated Services Digital Network (ISDN) - Basic Access Interface for S and T Reference Points (Layer 1 Specification)《综合服务数字网络(ISDN).S和T基准点的基本访问接口(第一层规范)》.pdf
  • ANSI T1.609-1999 Interworking between the ISDN User-Network Interface Protocol and the Signalling System Number 7 ISDN User Part《电信.ISDN用户间网络接口协议和7号信令系统ISDN用户部分间的互连》.pdf ANSI T1.609-1999 Interworking between the ISDN User-Network Interface Protocol and the Signalling System Number 7 ISDN User Part《电信.ISDN用户间网络接口协议和7号信令系统ISDN用户部分间的互连》.pdf
  • ANSI T1.610a-1998 Telecommunications - Generic Procedures for the Control of ISDN Supplementary Services - Modification to the Redirecting Number Information Element《电信.ISDN补充服务控制的.pdf ANSI T1.610a-1998 Telecommunications - Generic Procedures for the Control of ISDN Supplementary Services - Modification to the Redirecting Number Information Element《电信.ISDN补充服务控制的.pdf
  • ANSI T1.612-1992 Telecommunications – Integrated Services Digital Network (ISDN) – Terminal Adaptation Using Statistical Multiplexing《通信.综合业务数字网(ISDN).用统计多路传输的终端适配器》.pdf ANSI T1.612-1992 Telecommunications – Integrated Services Digital Network (ISDN) – Terminal Adaptation Using Statistical Multiplexing《通信.综合业务数字网(ISDN).用统计多路传输的终端适配器》.pdf
  • ANSI T1.613-1991 Telecommunications – Integrated Services Digital Network (ISDN) – Call Waiting Supplementary Service《远程通信.综合业务数字网(ISDN).呼叫等待辅助服务》.pdf ANSI T1.613-1991 Telecommunications – Integrated Services Digital Network (ISDN) – Call Waiting Supplementary Service《远程通信.综合业务数字网(ISDN).呼叫等待辅助服务》.pdf
  • ANSI T1.614-1991 Telecommunications – Integrated Services Digital Network (ISDN) – Packet Mode Bearer Service Category Description《远程通信.综合业务数字网(ISDN).分组模式载体业务种类描述》.pdf ANSI T1.614-1991 Telecommunications – Integrated Services Digital Network (ISDN) – Packet Mode Bearer Service Category Description《远程通信.综合业务数字网(ISDN).分组模式载体业务种类描述》.pdf
  • ANSI T1.615-1992 Digital Subscriber Signalling System No.1 (DSS1) - Layer 3 Overview《第1号数字用户信令系统(DSS1).第3层概述》.pdf ANSI T1.615-1992 Digital Subscriber Signalling System No.1 (DSS1) - Layer 3 Overview《第1号数字用户信令系统(DSS1).第3层概述》.pdf
  • ANSI T1.616-1992 Integrated Services Digital Network (ISDN) - Call Hold Supplementary Service《综合服务数字网络(ISDN).呼叫保持辅助服务》.pdf ANSI T1.616-1992 Integrated Services Digital Network (ISDN) - Call Hold Supplementary Service《综合服务数字网络(ISDN).呼叫保持辅助服务》.pdf
  • 相关搜索

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

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