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

上传人:李朗 文档编号:498194 上传时间:2018-11-28 格式:DOC 页数:5 大小:29.50KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷263及答案与解析.doc_第1页
第1页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷263及答案与解析.doc_第2页
第2页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷263及答案与解析.doc_第3页
第3页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷263及答案与解析.doc_第4页
第4页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷263及答案与解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 263及答案与解析 一、程序填空题 1 下列给定程序中,函数 fun的功能是:把形参 a所指数组中的偶数按原顺序依次存放到 a0、 a1、 a2 中,把奇数从数组中删除,偶数的个数通过函数值返回。 例如,若 a所指数组中的数据最初排列为: 9、 1、 4、 2、 3、 6、 5、 8、 7,删除奇数后, a所指数组中的数据为: 4、 2、 6、 8,返回值为 4。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的 结构 ! 试题程序: #include stdio h #

2、define N 9 int fun(int a, int n) int i, j; j=0; for(i=0; i n; i+) *found* if(【 1】 =0) *found* 【 2】 =ai; j+; *found* return【 3】 ; main() int bN=9, 1, 4, 2, 3, 6, 5, 8, 7), i, n; printf(“ nThe original data: n“); for(i=0; i N; i+) printf(“ 4 d“, bi); printf(“ n“); n=fun(b, N); printf(“ nThe number of

3、even d n“, n); printf(“ nThe even: n“); for(i=0; i n; i+) printf(“ 4d“, bi); printf(“ n“); 二、程序修改题 2 下列给定程序中, fun函数的功能是:分别统计字符串中大写字母和小写字母的个数。 例如,给字符串 s输入: AAaaBBbb123CCcccd,则应输出: upper=6, lower=8。请改正程序中的错误,使它得出正确的结果。 注意:部分源程序在文件 MODI1 C中,不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: 1 #include stdio h 2 *f

4、ound* 3 void fun(char*s, int a, int b) 4 5 while(*S) 6 if(*S =A *s =z) 7 *found* 8 * a=a+1; 9 if(*s =a *s =z) 10 *found* 11 *b=b+1; 12 s+; 13 14 15 main() 16 char S100; int upper=0, 17 lower=0; 18 printf(“ nPlease a string: “); 19 gets(S); 20 fun(S, upper, &lower); 21 printf(“ n upper= d lower= d n“

5、 upper, lower); 22 三、程序设计题 3 请编写函数 fun,其功能是:将放在字符串数组中的 M个字符串 (每串的长度不超过 N),按顺序合并组成一个新的字符串。 例如,若字符串数组中的 M个字符串为 “AAAA“, “BBBBBBB“, “CC“,则合并后的字符串内容应该是 “AAAABBBBBBBCC”。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio h #include conio h #define M 3 #define N 20 void fu

6、n(char aMN, char*b) void main() char wMN=“AAAA“, “BBBBBBB“, “CC“; char a100=“#“); int i; printf(“The string: n“); for(i=0; i M; i+) puts(wi); printf(“ n“); fun(w, a); printf(“The A string: n“); printf(“ s“, a); printf(“ n n“); 国家二级 C语言机试( 操作题)模拟试卷 263答案与解析 一、程序填空题 1 【正确答案】 (1)ai 2 (2)aj (3)j 【试题解析】

7、填空 1: if语句条件表达式,判断数组元素是否为偶数,对 2求余,结果为 0,则为偶数;结果为 1则为奇数。 填空 2:如果该数组元素是偶数,则将其值保存。 填空 3:最后按要求将偶数个数通过 return语句返回给 main函数。 二、程序修改题 2 【正确答案】 (1)void fun(char*s, int*a, int*b) (2)*a=*a+1; (3)*b=*b+1; 【试题解析】 (1)由主函数中调用 fun函数的语句 fun(s, &upper, &lower)可知,函数的后两个变量为指针的形式,所以用 *a和 *b。 (2)*a的作用是用来记录大写字母的个数,此处的作用是对

8、 *a累加 1,所以此处应改为 *a=*a+1。 (3)*b的作用是用来记录小写字母的个数,此处的作用是对 *b累加 1,所以此处应改为 *b=*b+1。 三、程序设计题 3 【正确答案】 void fun(char aMN, char*b) int i, j, k=0; for(i=0; i M; i+) *将字符串数组中的 M个字符串,按顺序存入一个新的字符串 * for(j=0; aij!= 0; j+) bk+=aij; bk= 0; *在字符串最后加上字符串结束标记符 * 【试题解析】 本题考查:字符串连接操作。本程序中第 1个 for循环的作用是对二维数组行的控制,第 2个循环的作用是从同一行中取出字符并存放到一维数组 b中,语句是 bk+=aij;。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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