[计算机类试卷]国家二级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循环语句直接把偶数筛出去,确保参与操作的数均为奇数。

展开阅读全文
相关资源
猜你喜欢
  • ASTM B870-2008(2014) Standard Specification for Copper-Beryllium Alloy Forgings and Extrusions Alloys &40 UNS Nos C17500 and C17510&41 《铜-铍合金锻制和挤制合金C17500和C17510的标准规格》.pdf ASTM B870-2008(2014) Standard Specification for Copper-Beryllium Alloy Forgings and Extrusions Alloys &40 UNS Nos C17500 and C17510&41 《铜-铍合金锻制和挤制合金C17500和C17510的标准规格》.pdf
  • ASTM B871-2001(2007) Standard Test Method for Tear Testing of Aluminum Alloy Products《铝合金产品撕裂测试的标准试验方法》.pdf ASTM B871-2001(2007) Standard Test Method for Tear Testing of Aluminum Alloy Products《铝合金产品撕裂测试的标准试验方法》.pdf
  • ASTM B872-2006 Standard Specification for Precipitation-Hardening Nickel Alloys Plate Sheet and Strip《淀积硬化镍合金金属板、薄板和带材的标准规范》.pdf ASTM B872-2006 Standard Specification for Precipitation-Hardening Nickel Alloys Plate Sheet and Strip《淀积硬化镍合金金属板、薄板和带材的标准规范》.pdf
  • ASTM B872-2006(2011) Standard Specification for Precipitation-Hardening Nickel Alloys Plate Sheet and Strip《淀积硬化镍合金金属板 薄板和带材的标准规范》.pdf ASTM B872-2006(2011) Standard Specification for Precipitation-Hardening Nickel Alloys Plate Sheet and Strip《淀积硬化镍合金金属板 薄板和带材的标准规范》.pdf
  • ASTM B872-2006(2016) Standard Specification for Precipitation-Hardening Nickel Alloys Plate Sheet and Strip《沉淀硬化镍合金板材 薄板材和带材的标准规格》.pdf ASTM B872-2006(2016) Standard Specification for Precipitation-Hardening Nickel Alloys Plate Sheet and Strip《沉淀硬化镍合金板材 薄板材和带材的标准规格》.pdf
  • ASTM B873-2001(2007) Standard Test Method for Measuring Volume of Apparent Density Cup Used in Test Methods B212 B329 and B417《B212 B329和B417的测试方法中用的表观密度杯的容积测量的标准试验方法》.pdf ASTM B873-2001(2007) Standard Test Method for Measuring Volume of Apparent Density Cup Used in Test Methods B212 B329 and B417《B212 B329和B417的测试方法中用的表观密度杯的容积测量的标准试验方法》.pdf
  • ASTM B873-2012 Standard Test Method for Measuring Volume of Apparent Density Cup Used in Test Methods B212 B329 and B417《B212、B329和B417测试方法中用表观密度杯的容积测量的标准试验方法》.pdf ASTM B873-2012 Standard Test Method for Measuring Volume of Apparent Density Cup Used in Test Methods B212 B329 and B417《B212、B329和B417测试方法中用表观密度杯的容积测量的标准试验方法》.pdf
  • ASTM B873-2017 Standard Test Method for Measuring Volume of Apparent Density Cup Used in Test Methods B212 B329 and B417《测量试验方法B212 B329和B417使用表观密度杯容量的标准试验方法》.pdf ASTM B873-2017 Standard Test Method for Measuring Volume of Apparent Density Cup Used in Test Methods B212 B329 and B417《测量试验方法B212 B329和B417使用表观密度杯容量的标准试验方法》.pdf
  • ASTM B874-1996(2003) Standard Specification for Chromium Diffusion Coating Applied by Pack Cementation Process《用于固体渗金属处理的铬扩散镀层的标准规范》.pdf ASTM B874-1996(2003) Standard Specification for Chromium Diffusion Coating Applied by Pack Cementation Process《用于固体渗金属处理的铬扩散镀层的标准规范》.pdf
  • 相关搜索

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

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