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

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

1、国家二级 C语言机试(操作题)模拟试卷 480及答案与解析 一、程序填空题 1 下列给定程序中,函数 fun的功能是:求 ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参 n所指的变量中。 ss所指字符串数组中共有 M个字符串,且串长小于 N。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #include string h #define M 5 #define N 20 int fun(char(*ss)N, in

2、t*n) int i, k=0, fen=N; /*found*/ for(i=0; i 【 1】 ; i+) fen=str1en(ssi); if(i=0) *n=1en; /*found*/ if(fen【 2】 *n) *n=fen; k=i; /*found*/ return(【 3】 ); main() char ssMN=“shang hai“, “guangzhou“, “beijing“, “ tianjirig”, ”chongqing”); int n, k, i ; printf(“nThe original strings aEe: n“); for(i=0; i M

3、 i+)puts(ss i); k=fun(ss, &n); printf(“nThe length of shortest string is: dn“, n); printf(“nThe shortest string is: sn“, ssk); 二、程序修改题 2 下列给定程序中函数 fun的功能是:将 tt所指字符串中的小写字母全部改为对应的大写字母,其他字符不变。 例如,若输入 “Ab, cD”,则输出 “AB, CD”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #inClude conio

4、h #include stdio h #include string h char*fun(char tt) int i; for(i=0; tti; i+) /*found*/ if(tti =a)|(tti =z) /*found*/ tti+=32; return(tt); main() char tt81; print: f(“nPiease enter a string: “); gets(tt); printf(“nThe result stringis: n s“, fun(tt); 三、程序设计题 3 编写函数 fun,其功能是:将所有大于 1小于整数 m的非素数存入 xx所指

5、数组中,非素数的个数通过 k返回。 例如,若输入 17,则应输出: 4 6 8 9 10 12 14 15 16。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdlib h #include conio h #include stdio h void fun(int m, int*k, int xx ) void main() int m, n, zz100; system(“CLS“); printf (“nPlease enter an integer number betw

6、een 10 and 100; “); scanf(“ d“, &n); fun(n, &m, zz); printf(“nnThere are dnonprime numbers less than d: “, m, n); for(n=0; n m; n+) printf(“n 4 d“, zz n); 国家二级 C语言机试(操作题)模拟试卷 480答案与解析 一、程序填空题 1 【正确答案】 (1)M (2) (3)k 【试题解析】 本题考查: for循环语句的循环条件; if语句条件表达式; return语句完成函数值的返回。 填空 1:题目指出 ss所指字符串数组中共有 M个字符串,

7、所以 for循环语句的循环条件是 i M。 填空 2:要求求长度最短的字符串, *n中存放的是已知字符串中长度最短的字符串的长度,将当前字符串长度与 *n比较,若小于 *n,则将该长度值赋给 *n,因此if语句的条件表达式为 len *n。 填空 3:将最短字符串的行下标作为函数值返回,变量 k存储行下标的值。 二、程序修改题 2 【正确答案】 (1)if(tti =a)&(tti =z) (2)tti一 =32; 【试题解析】 本题考查: if语句条件表达式;小写字母转换为大写字母的方法。 (1)分析本题可知,要判断字符是否为小写字母,即判断其是否在 a一 z之间,所以这里需要进行连续的比较

8、用 &。 (2)从 ASCII码表中可以看出,小写字母的 ASCII码值比对应大写字母的 ASCII值大 32。将字符串中的小写字母改为大写字母的方法是:从字符串第一个字符开始,根据 ASCII码值判断该字 母是不是小写字母,若是,则 ASCII码值减 32。 三、程序设计题 3 【正确答案】 void fun (int m, int *k,int xx ) int i,j,n =0; for(i=4; i m; i+)/* 找出大于 1小于整数 m的非素数 */ for(j=2; j i; j+) if (i j=0) break; if(j i) xxn+=i; *k=n; /*返回非素数的个数 */ 【试题解析】 本题考查:如何判断非素数;循环判断结构;数组的 引用。 题目要求将 1一 m之间的非素数存入数组中,应使用循环判断结构。循环语句用来遍历 1 m之间 的每个数,判断语句用来判断该数是否为素数,若不是素数,则将其存入数组中。本题是考查一个数是否为素数的简单延伸,只要掌握了判断素数的方法,问题便能顺利解决。 判定一个数是否为素数,即判断该数是否除了能被 1和它本身整除外,不能被任何数整除。 代码实现如下: for(j=2; j i; j+) if(i j=0) /*如果余数为 0,证明 1不是素数 */ 此语句需要熟记,很多判断素数的题目可通过此法解决。

展开阅读全文
相关资源
猜你喜欢
  • 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