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

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

1、国家二级( C语言)机试模拟试卷 167及答案与解析 一、程序填空题( 30分) 1 给定程序中已建立一个带有头结点的单向链表,在 main函数中将多次调用 fun函数,每调用一次 fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANKI C中。 不得增行或删行,也不得更改程序的结构 ! #include #include #define N 8 typedef struct list int data; struct 1ist*next; SLIST; void f

2、un(SLIST*p) SLIST*t, *s; t=p next; s=p; while(t next!=NULL) s=t; *found* t=t 【 1】; /*found*/ printf(” d”, 【 2】 ); s-next=NULL; *found*/ free(【 3】 ); SLIST*Crearlist(int *a) SLIST*h, *p, *q; int i; h=p=(SLIST*)malloc(sizeof(SLIST); for(i=0; idata=ai; p next=q; p=q; P next=0; return h; void outlist(SL

3、IST*h) SLIST*p; p=h next ; if(p=NULL)printf(” nThe list iS NULL! n”); else (printf(” nHead”); doprintf(” d”, p data); p=p next; while(p!=NULL); printf(” End n”); main() SLIST*head; int aN=11, 12, 15, 18, 19, 22, 25, 29; head=creatlist(a); printf(” nOutput from head: n”); outlist(head); printf(” nOut

4、put from tail: n”); while (head next !=NULL) fun(head); printf(” n n”); print ( ” nOutput from head again: n”), outlist(head); 二、程序修改题( 30分) 2 给定程序 MODII C中函数 fun的功能是:计算 S=f(-n)+f(一n+1)+f(0)+f(1)+f(2)+fi(n) 的值。例如,当 n为 5时,函数值应为:10 407143。 f(x)函数定义如下: 请改正程序中的错误,使程序能输出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更

5、改程序的结构 !#include #include /*found*/f(double x) if (x = 0.0 | x = 2.0) return 0.0; else if (x data (3)t 【试题解析】 第一空: fun函数中的循环 “while(I-next !=NULL)“目的是找到尾结点,利用结点变量 s和 t, s指向当前节点, t不断指向下一个结点,因此第一空处应该是 “t=t-next; “。 第二空:这里是输出尾结点中的数据,已经利用循环找到了尾结点 t, t的数据是 t-data,因此第二空处应该为 “printf(“ d“, t-dam); “。 第三空:输出

6、尾结点数据之后删除尾结点,使用 free,又因为尾结点是 t,因此第三空处应该为 “free(t); “。 二、程序修改题( 30分) 2 【正确答案 】 double f(double x) return s; 【试题解析】 ( 1)第一个标识下 f函数的定义缺少返回值类型,所以将“f(double x)”改为 “double f(double x)”。 ( 2)第二个标识下返回语句没有分号结束。所以,第二个标识下 “return s”应该改为 “return s;”。 三、程序设计题( 40分) 3 【正确答案】 int i; double avg=0 0, sum=0 0, abs=0 0, fc; for(i=0; i10 ; i+)sum+=xi; avg=sum 10; *计算平均值 * for(i=0; i10; i+) abs+=(xi-aVg)*(xi一 avg); fc=sqrt(abs 10); return fc; 【试题解析】 (1)首先计算 x的值,它的值是所有值累加求和的十分之一。 (2)根号下的部分是前面求得 x与当前项差的平方的累加和的十分之一。 (3)最后可以利用 C语言库函数 pow来计算平方根。

展开阅读全文
相关资源
猜你喜欢
  • BS PD ISO TR 80001-2-7-2015 Application of risk management for IT-networks incorporating medical devices Application guidance Guidance for Healthcare Delivery Organizations (HDOs) .pdf BS PD ISO TR 80001-2-7-2015 Application of risk management for IT-networks incorporating medical devices Application guidance Guidance for Healthcare Delivery Organizations (HDOs) .pdf
  • BS PD ISO TS 11999-2-2015 PPE for firefighters Test methods and requirements for PPE used by firefighters who are at risk of exposure to high levels of heat and or flame while figh.pdf BS PD ISO TS 11999-2-2015 PPE for firefighters Test methods and requirements for PPE used by firefighters who are at risk of exposure to high levels of heat and or flame while figh.pdf
  • BS PD ISO TS 13399-71-2016 Cutting tool data representation and exchange Graphical data layout Creation of documents for standardized data exchange Graphical product information《切削.pdf BS PD ISO TS 13399-71-2016 Cutting tool data representation and exchange Graphical data layout Creation of documents for standardized data exchange Graphical product information《切削.pdf
  • BS PD ISO TS 13399-72-2016 Cutting tool data representation and exchange Creation of documents for the standardized data exchange Definition of properties for drawing header and th.pdf BS PD ISO TS 13399-72-2016 Cutting tool data representation and exchange Creation of documents for the standardized data exchange Definition of properties for drawing header and th.pdf
  • BS PD ISO TS 15926-11-2015 Industrial automation systems and integration Integration of life-cycle data for process plants including oil and gas production facilities Methodology f.pdf BS PD ISO TS 15926-11-2015 Industrial automation systems and integration Integration of life-cycle data for process plants including oil and gas production facilities Methodology f.pdf
  • BS PD ISO TS 16550-2014 Nanotechnologies Determination of silver nanoparticles potency by release of muramic acid from $iS$it$ia$ip$ih$iy$il$io$ic$io$ic$ic$iu$is $ia$iu$ir$ie$iu$is.pdf BS PD ISO TS 16550-2014 Nanotechnologies Determination of silver nanoparticles potency by release of muramic acid from $iS$it$ia$ip$ih$iy$il$io$ic$io$ic$ic$iu$is $ia$iu$ir$ie$iu$is.pdf
  • BS PD ISO TS 17822-1-2014 $iI$in $iv$ii$it$ir$io diagnostic test systems Qualitative nucleic acid-based $ii$in $iv$ii$it$ir$io examination procedures for detection and identificati.pdf BS PD ISO TS 17822-1-2014 $iI$in $iv$ii$it$ir$io diagnostic test systems Qualitative nucleic acid-based $ii$in $iv$ii$it$ir$io examination procedures for detection and identificati.pdf
  • BS PD ISO TS 17865-2016 Geometrical product specifications (GPS) Guidelines for the evaluation of coordinate measuring machine (CMM) test uncertainty for CMMs using single and mult.pdf BS PD ISO TS 17865-2016 Geometrical product specifications (GPS) Guidelines for the evaluation of coordinate measuring machine (CMM) test uncertainty for CMMs using single and mult.pdf
  • BS PD ISO TS 17951-1-2016 Water quality Determination of fluoride using flow analysis (FIA and CFA) Method using flow injection analysis (FIA) and spectrometric detection after off.pdf BS PD ISO TS 17951-1-2016 Water quality Determination of fluoride using flow analysis (FIA and CFA) Method using flow injection analysis (FIA) and spectrometric detection after off.pdf
  • 相关搜索

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

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