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

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

1、国家二级 C语言机试(操作题)模拟试卷 322及答案与解析 一、程序填空题 1 围绕山顶一圈有 N个山洞,编号为 0、 1、 2、 3、 、 N 1,有一只狐狸和一只兔子在洞中居住。狐狸总想找到兔子并吃掉它,它的寻找方法是先到第一个洞(即编号为 0的洞 )中找;再隔 1个洞,即到编号为 2的个洞中找;再隔 2个洞,即到编号为 5的洞中找;下次再隔 3个洞;即到编号为 9的洞中找; 。若狐狸找一圈,请为兔子指出所有不安全的洞号。程序中用 a数组元素模拟一个洞,数组元素的下标即为洞号,数组元素中的值为 0时,表示该洞安全,为 1时表示该洞 不安全。若形参 n的值为 30时,不安全的洞号是 0、 2

2、 5、 9、 14、 20、 27。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1 C中。不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #define N 100 void fun(int*a, int n) int i, t; for(i=0; i n; i+) *found* ai=【 1】 ; i=0; *found* 【 2】 =1; while(i n) ai=1; t+; *found* i=【 3】 ; main() int aN, i, n=30; fun(a,

3、 n); for(i=0; i n; i+) if(ai=1) printf(“不安全的洞号是: d n“, i); 二、程序修改题 2 下列给定程序的功能是:读入一个英文文本行,将其中每个单词的第一个字母改成大写,然后输出此文本行 (这里 ”单词 ”是指由空格隔开的字符串 )。例如,若输入“I am a student to takethe examination“,则应输出 “I Am A Student To TakeThe Examination“。 请改正程序中的错误,使程序能得出正确的结果。 注意:部分源程序在文件 MODI1 C中,不要改动 main函数,不得增行或删行,也不得更

4、改程序的结构 ! 试题程序: 1 #include stdlib h 2 #include string h 3 #include conio h 4 #include ctype h 5 #include stdio h 6 #include string h 7 *found* 8 void upfst(char P) 9 10 int k=0; 11 for(; *P; P+) 12 if(k) 13 14 if(*P=) 15 k=0; 16 17 else 18 19 if(*P!=) 20 21 k=1; 22 *P=toupper(*P); 23 24 25 26 void ma

5、in() 27 28 char chrstr81j 29 System(“CLS“); 30 printf(“ nPlease enter an English text; lihe: “); 31 gets(chrstr); 32 printf(“ nBofore changing: n s“, chrstr); 33 upfst(chrstr); 34 printf(“ nAfter changing: n s n“, chrstr); 35 三、程序设计题 3 请编写函数 fun,其功能是:计算并输出下列多项式的值。例如,当 n=10时 ,函数值为 0 909091。注意:部分源程序在文

6、件 PROG1 C中。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序: #include conio h#include stdio h #include stdlib h double fun(int n)void main() FILE*wf; system(“CLS“); printf(“ f n“, fun(10); * wf=fopen(“out dat“, “w“); fprintf(wf, “ f“, fun(10); fclose(wf);* 国家二级 C语言机试(操作题)模拟试卷 322答案与解析 一、程序填空题 1

7、正确答案】 (1)0 (2)t (3)i+t 【试题解析】 首先为数组所有元素赋初值 0,利用循环为符合条件的数组赋值为1,并计算下一个数据的下标。设置一个变量存放间隔数,每次循环间隔数加 1。本次下标加间隔数加 1为下一个下标。 填空 1:利用循环为数组所有元素赋值为 0。 填空 2:变量 t为 间隔数,在循环过程中每次加 1,设定初始值为 11。 填空 3:下一个数组下标为本次的下标加间隔数加 1的值。 二、程序修改题 2 【正确答案】 void upfst(char*p) 【试题解析】 主函数中 fun函数的调用方式说明函数 fun的参数应为指针类型。 三、程序设计题 3 【正确答案】 double fun(int n) int i; double s=0 0; for(i=1; i =n; i+) s=s+1 0 (i*(i+1); *求级数的和 * return S; 【试题解析】 本题要求级数的和,由多项式的形式可知,应使用循环语句实现,循环的通项为 1 n(n+1)。本程序首先定义了和变量及循环变量,然后运用一个for语句求出级数的和,最后将和变量 s返回。

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