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

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

1、国家二级 C语言机试(操作题)模拟试卷 602及答案与解析 一、程序填空题 1 使用 VC+2010打开考生文件夹下 blank1中的解决方案。此解决方案的项目中包含一个源程序文件 blank1 c。在此程序中,函数 fun的功能是将不带头结点的单向链表逆置,即若原链表中从头至尾结点数据域依次为 2、 4、 6、 8、 10,逆置后,从头至尾结点数据域依次为 10、 8、 6、 4、 2。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构 ! 试 题程序: #include stdio h #include

2、 stdlib h #define N5 typeclef struct node int data; struct node*next; NODE; *found* 【 1】 *fun(NODE*h) NODE*p, *q, *r; p=h; if(p=NULL) return NULL; q=p- next; p- next=NULL; while(q) *found* r=q- 【 2】 ; q- next=p; p=q; *found* q=【 3】 ; return p; NODE*creatlist(int a) NODE*h, *p, *q; int i; h=NULL; for

3、i=0; i N; i+) q=(NODE*)malloc(sizeof (NODE); q- data=ai; q- next=NULL; if(h=NULL)h=p=q; elsep- next; =q; p=q; return h; void outliSt(NODE*h) NODE*p; p=h; if(p=NULL) printf(“The list is NULL! n“); else printf(“ nttead“); do printf(“- d“, p- data); p=p- next; while(P!=NULL); prAntf(“- End n“j; main()

4、 NODE*head; int aN=2, 4, 6, 8, 10; head=creatlist(a); printf(“ nThe original list: n“); outlist(head); head=fun(head); printf(“ nThe list after inverting: n“); outlist(head); 二、程序修改题 2 使用 VC+2010打开考生文件夹下 modi1中的解决方案。此解决方案的项目中包含一个源程序文件 modi1 c。在此程序中,函数 fun的功能是:在字符串的最前端加入 n个 *号,形成新串,并且覆盖原串。 字符串的长度 最长允

5、许为 79。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 NODI1 C中,不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #include string h void fun(char s, int n) char a80, *p; int i; *found* s=p; for(i=0; i n; i+)ai=*; do ai=*p; i+; *found* while(*p+) ai=0; strcpy(s, a); main() (int n; char s80; printf(“ nEnter a

6、 string: “); gets(s); printf(“ nThe string “ s “ n“, s); printf(“ ngnter n(number of*): “); scanf(“ d“, &n); fun(s, n); printf(“ nThe string after insert: “ s “ n“, s), 三、程序设计题 3 使用 VC+2010打开考生文件夹下 prog1中的解决方案。此解决方案的项目中包含一个源程序文件 prog1 c。在此程序中,请编写函数 void fun(int x, int pp,int*n),它的功能是:求出能整除 x且不是偶数的各整

7、数,并按从小到大的顺序放在 pp所指的数组中,这些除数的个数通过形参 n返回。 例如,若 x中的值为 30,则有 4个数符合要求,它们是 1、 3、 5、 15。 注意 :部分源程序在文件 PROG1 c中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include conio h #include stdio h #include stdlib h void fun(int x, int pp, int: *n) void main() FTLE*wf; int x, aa1000, n, i; system(“CLS“)

8、 printf(“ nPlease enter an integer number: n“); scanf(“ d“, &x); fun(x, aa, &n); for(i=0ji n; i+) printf(“ d“, aai); printf(“ n“); *found* wf=fopen(“out dat“, “w“); fun(30, aa, &n); for(i=0; i n; i+) fprintf: f(wf, “ d“, aai); fclose(wf); *found* 国家二级 C语言机试(操 作题)模拟试卷 602答案与解析 一、程序填空题 1 【正确答案】 (1)NO

9、DE (2)next (3)r 【试题解析】 填空 1:本题考查了函数指针变量的函数返回值的类型,*fun(NODE*h)的返回值为 p,而 p的数据类型为 NODE,因此本空应该填写NODE。 填空 2:从此空的形式 p-可知本空应该填写 next。 填空 3:本题要求将不带头结点的单向链表逆置,为了使 q的指针向后移,此空应该填写 r。 二、程序修改题 2 【正确答案】 (1)p=s; (2)while(*p+); 【试题 解析】 (1)指针 p应指向 s,所以应改为 p=s;。 (2)循环等待,当 while循环执行一次,临时变量 p应该指向字符串的下一位置,所以应改为 while(*p

10、);。 三、程序设计题 3 【正确答案】 void fun(int x, int pp, int*n) int i, j=0; for(i=1; i =x; i=i+2) *i的初始值为 1,步长为 2,确保 i为奇数 * if(x i=0) *将能整除 x的数存入数组 pp中 * ppj+=i; *n=j; *传回满足条件的数的个数 * 【试题解析】 本题考查:偶数的判定方法;整除的实现。 本题题干信息是:能整除 x且不是偶数的所有整数。循环语句中变量 i从 1开始且每次增 2,所以 i始终是奇数。 整除的方法,已经讲过多次,这里就不再赘述了。对于本题目要求的不是偶数的判定方法,即该数对 2求余不为 0。除本题描述的方法外,还可以通过 for循环语句直接把偶数筛出去,确保参与操作的数均为奇数。

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