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

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

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

2、define N 9 3 int fun(int a, int n) 4 int i, j; 5 j=0; 6 for(2=0; i n; i+) 7 *found* 8 if(_1_=0) 9 *found* 10 _2_ =ai; j+; 11 12 *found* 13 return _3_; 14 15 main() 16 int bN=9, 1, 4, 2, 3, 6, 5, 8, 7, i, n; 17 printf( nThe original data: n); 18 for(i=0; i N; i+) printf( 4d, bi); 19 printf( n); 20 n=

3、fun(b, N); 21 printf( nThe number of even: d n, n); 22 printf( nThe even: n); 23 for(2=0; i n; i+)printf( 4d, bi); 24 printf( n); 25 二、程序修改题 2 给定程序 MODI1 C中的函数 Creatlink的功能是创建带头结点的单向链表,并为各结点数据域赋 0到 m-1的值。 请改正函数 Creatlink中指定部位的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得 更改程序的结构 ! 1 #include stdio h 2 #

4、include stdlib h 3 typedef struct aa 4 int data; 5 struct aa *next; 6 NODE; 7 NODE *Creatlink(int n, int m) 8 NODE * h=NULL, *p, *s; 9 int i; 10 *found* 11 p=(NODE)malloc(sizeof(NODE); 12 h=p; 13 p- next=NULL; 14 for(i=1; i =n; i+) 15 s=(NODE *)malloc(sizeof(NODE); 16 s- data=rand() m; s- next=p- ne

5、xt; 17 p- next=s; p=p- next; 18 19 *found* 20 return p; 21 22 outlink(NODE *h) 23 NODE *p; 24 p=h- next; 25 printf( nXnTHE LIST: n n HEAD); 26 while(p) 27 printf(- d, p- data); 28 p=p- next; 29 30 printf( n); 31 main() 32 NODE *head; 33 head=Creatlink(8, 22); 34 outlink(head); 三、程序设计题 3 请编写函数 fun,其功

6、能 是分别统计形参 t所指二维数组中字母 A和 C的个数。 注意:部分源程序存在 PROG1 C中,请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入所编写的若干语句。 1 #nclude stdio h 2 #include stdlib h 3 #define M 14 4 void NONO(); 5 void fun(char(*t)N, int*a, int*c) 6 7 8 void get(char(*s)M) 9 int i, j; 10 for(i=0; i M; i+) 11 for(j=0; j M; j+) 12 sij=65+rand()

7、12; 13 printf( c, sij); 14 printf( n); 15 16 17 main() 18 char aMM; 19 int x, y; 20 get(a); 21 fun(a, x, y); 22 printf(A= d C= d n, x, y); 23 NONO(); 24 25 void NONO() 26 *本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 * 27 FILE *fp, *wf; 28 int i, j, x, y; 29 char aMM; 30 fp=fopen(in dat, r); 31 wf=fopen(out dat,

8、w); 32 for(i=0; i M; i+) 33 for(j=0; j M; j+) 34 fscanf( fp, c , aij); 35 36 Fun(a, x, y); 37 fprintf(wf, A= d n, x); 38 fprintf(wf, C= d n, y); 39 fclose(fp); 40 fclose(wf); 41 国家二级 C语言机试(操作题)模拟试卷 353答案与解析 一、程序填空题 1 【正确答案】 (1)ai 2 (2)aj (3)j 【试题解析】 函数 fun的功能是把形参 a所指数组中的偶数按原顺序依次存放到a,把奇数从数组中删除。 第一空:由

9、 “_2_ =ai; j+; ”是将偶数元素保存起来并且计数变量加 1,可知 i记录了偶数元素的个数,第一空处是判断 ai是否是偶数,因此第一空处应为“ai 2”。 第二空: a所指数组中的偶数按原顺序依次存放到 a0、 a1、 a2 , j初始化为 0, aj就可以将偶数元素存放在 a中,故第二空处应为 “aj”。 第三空: fun函数的返回值是偶数个数,故第三空处应为 “i”。 二、程序修 改题 2 【正确答案】 (1)p=(NODE*)malloc (sizeof(NODE); (2)return h; 【试题解析】 (1)“p=(NODE)malloc(sizeof(NODE); ”第

10、一标识, maclloc函数的返回类型是 void*类型,表示未确定类型的指针,因此需要指针类型转换,而“(NODE)”不是指针类型,故第一标识下应改成“p=(NODE*)malloc(sizeof(NODE); ”。 (2)第二个标识下,最后将单链表返回,应该是返回头指针 h指向的链表,而不是其中的一个节点 p,所以 “return p; ”应该改为 “return h; ”。 三、程序设计题 3 【正确答案】 5 void fun( char (*t)M, int *a , int *c) 6 int i, j; 7 *a=0; *c=0; 8 for( i=0; i M; i+) 9 f

11、or(j=0; j M; j+) 10 if(tij=A)*a=*a+1 ; 11 else if(tij=c)*c=*c+1 ; 12 【试题解析】 本题首先需要一个二维数组,二维数组的大小在程序开始就进行了定义 “define=14”,这个大小比较合适,然后利用 gets函数得到数组,然后数据就可以进入 fun函数中进行处理应用。进入。 fun函数, fun函数首先肯定需要 for循环语句将二维数组中的数据进行排序使用,然后需要条件语句进行判断处理,这两步是一体,见程序第 9 11行, for循环保证全部使用了二维数组中数据,并且是依次使用, if语句判断了字母是否为 A或者 C或者都不是,并且进行了统计相加得到了 A的个数 a, C的个数 c,这样循环 完成后, A和 C的个数 a、 c就能继续返回主函数进行输出了,见程序 26行,最终得到结果。

展开阅读全文
相关资源
猜你喜欢
  • API MPMS 18.2-2016 Manual of Petroleum Measurement Standards Chapter 18.2 Custody Transfer of Crude Oil from Lease Tanks Using Alternative Measurement Methods (FIRST EDITION).pdf API MPMS 18.2-2016 Manual of Petroleum Measurement Standards Chapter 18.2 Custody Transfer of Crude Oil from Lease Tanks Using Alternative Measurement Methods (FIRST EDITION).pdf
  • API MPMS 19.1-2017 Manual of Petroleum Measurement Standards Chapter 19.1 Evaporative Loss from Fixed-roof Tanks (FIFTH EDITION).pdf API MPMS 19.1-2017 Manual of Petroleum Measurement Standards Chapter 19.1 Evaporative Loss from Fixed-roof Tanks (FIFTH EDITION).pdf
  • API MPMS 19.3 PART A-1997 Manual of Petroleum Measurement Standards Chapter 19.3-Evaporative Loss Measurement - Part A-Wind Tunnel Test Method for the Measurement of Deck-Fitting Lr.pdf API MPMS 19.3 PART A-1997 Manual of Petroleum Measurement Standards Chapter 19.3-Evaporative Loss Measurement - Part A-Wind Tunnel Test Method for the Measurement of Deck-Fitting Lr.pdf
  • API MPMS 19.3 PART C-1998 Manual of Petroleum Measurement Standards Chapter 19.3-Evaporative Loss Measurement - Part C-Weight Loss Test Method for the Measurement of Rim-Seal Loss E.pdf API MPMS 19.3 PART C-1998 Manual of Petroleum Measurement Standards Chapter 19.3-Evaporative Loss Measurement - Part C-Weight Loss Test Method for the Measurement of Rim-Seal Loss E.pdf
  • API MPMS 19.3 PART D-2001 Manual of Petroleum Measurement Standards Chapter 19.3-Evaporative Loss Measurement - Part D-Fugitive Emission Test Method for the Measurement of Deck-Sea(.pdf API MPMS 19.3 PART D-2001 Manual of Petroleum Measurement Standards Chapter 19.3-Evaporative Loss Measurement - Part D-Fugitive Emission Test Method for the Measurement of Deck-Sea(.pdf
  • API MPMS 19.3 PART E-1997 Manual of Petroleum Measurement Standards Chapter 19.3-Evaporative Loss Measurement - Part E-Weight Loss Test Method for the Measurement of Deck-Fitting LR.pdf API MPMS 19.3 PART E-1997 Manual of Petroleum Measurement Standards Chapter 19.3-Evaporative Loss Measurement - Part E-Weight Loss Test Method for the Measurement of Deck-Fitting LR.pdf
  • API MPMS 19.6.1-2017 Manual of Petroleum Measurement Standards Chapter 19.6 Part 1-Evaporative Loss from Storage Tank Floating-roof Landings (FIRST EDITION).pdf API MPMS 19.6.1-2017 Manual of Petroleum Measurement Standards Chapter 19.6 Part 1-Evaporative Loss from Storage Tank Floating-roof Landings (FIRST EDITION).pdf
  • API MPMS 2.2G-2014 Manual of Petroleum Measurement Standards Chapter 2.2G Calibration of Upright Cylindrical Tanks Using the Total Station Reference Line Method (FIRST EDITION).pdf API MPMS 2.2G-2014 Manual of Petroleum Measurement Standards Chapter 2.2G Calibration of Upright Cylindrical Tanks Using the Total Station Reference Line Method (FIRST EDITION).pdf
  • API MPMS 2.8B-1995 Manual of Petroleum Measurement Standards Chapter 2 - Tank Calibration Section 8B - Recommended Practice for the Establishment of the Location of the Reference Gn.pdf API MPMS 2.8B-1995 Manual of Petroleum Measurement Standards Chapter 2 - Tank Calibration Section 8B - Recommended Practice for the Establishment of the Location of the Reference Gn.pdf
  • 相关搜索

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

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