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

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

1、国家二级 C语言机试(操作题)模拟试卷 423及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是: 用函数指针指向要调用的函数,并进行调用。 规定在 【 2】 处使 f指向函数 f1,在 【 3】 处使 f指向函数 f2。 当调用正确时,程序输出: x1=5 000000,x2=3 000000,x1*x1+x1*x2= 40 000000。 注意:部分源程序在文件 BLANK1 C中。 不得增行或删行,也不得更改程序的结构! 试题程序: #include stdio h double f1 (double x) return x*x; double f2 (double x,

2、 double y) return x*y; double fun (double a, double b) /*found*/ 【 1】 ( *f) (); double r1, r2; /*found*/ f=【 2】 ; r1=f(a); /*found*/ f=【 3】 ; r2=( *f) (a, b); return r1 + r2; main () double x1 =5, x2 =3, r, r = fun (xl, x2); printf (“nx1 = f, x2 = f, x1 * x1 +x1 * x2 = fn“,x1, x2, r) ; 二、程序修改题 2 下列给

3、定程序是建立一个带头结点的单向链表,并用随机函数为各结点赋值。函数 fun的功能是将单向链表结点(不包 括头结点)数据域为偶数的值累加起来,并且作为函数值返回。 请改正函数 fun中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODI1 C中,不要改动 maln函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include stdio h #include conio h #include stcilib h typedef struct aa int data; struct aa * next; NODE; int fun (NODE*h) int sum =0;

4、NODE *p; p = h一 next; /*found*/ while (p 一 next) if (p 一 data 2 =0) sum += p 一 data; /*found*/ p = h 一 next; return sum; NODE * creatlink (int n) NODE *h, *p, * s; int i; h=p=(NODE * ) malloc ( sizeof (NODE); for(i=1, i n ; i+) s=(NODE * ) malloc ( sizeof (NODE); s 一 data = rand () 16; s 一 next =p 一

5、 next; p 一 next = s; p =p 一 next; p 一 next = NULL; return h; outlink (NODE*h) NODE *p; p= h 一 next; printf (“nn The LIST :nn HEAD“) ; while (p) printf (“一 d“,p 一 data) ; p =p 一 next; printf “n“) ; void main () NODE *head; int sum; system ( “CLS“) ; head = creatlink (10) ; outlink (head) ; sum = fun

6、head) ; printf ( “ nSUM = d“, sum) ; 三、程序设计题 3 请编写函数 fun,该函数的功能是:判断字符串是否为回文,若是,则函数返回1,主函数中输出 ”YES”,否则返回 0,主函数中输出 ” NO”。回文是指顺读和倒读都一样的字符串。 例如,字符串 LEVEL是回文,而字符串 123312就不是回文。 注意:部分源程序在文件 PROG1 C中。 请勿改动主函数 maln和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio h #define N 80 int fun (char * str)

7、main () char sN ; FILE * out; char * test =“1234321“,“123421“, “123321“, “abcdCBA“ ; int i; printf (“Enter a string : “); gets (s) ; printf (“nn“) ; puts (s) ; if (fun (s) printf (“YESn“) ; else printf (“NOn“) ; /*/ out = fopen (“out dat“w“) ; if (fun (testi ) fprintf (out, “YESn“) ; else fprintf (o

8、ut, “NOn“) ; fclose (out) ; /*/ 国家二级 C语言机试(操作题)模拟试卷 423答案与解析 一、程序填空题 1 【正确答案】 (1)double (2)f1 (3)f2 【试题解析】 填空 1:( *f) ()代表一个指向函数的指针变量,而本题所被调用的 f1、 f2两函数的返回值均为 double型,因而此空应该填写 double。 填空 2:因为在给函数指针变量赋值时,只需给出函数名而不必给出参数,因而此空应该填写 f1。 填空 3:同填空 2,此空应该填写 f2。 相关知识点: (1)指向函数的指针变量的一般定义形式为:数据类型( *指针变量名) (); (

9、2)函数的调用可以通过函数名调用,也可以通过函数指针调用。 (3)在给函数指针变量赋值时,只需给出函数名而不必给出参数。 二、程 序修改题 2 【正确答案】 (1)while (p!=NULL) (2)p=p一 next; 【试题解析】 (1)判断当前指针 p指向的结点是否存在,若存在则对该结点数据域进行判断操作。 (2)判断结束后指针指向下一个结点。 三、程序设计题 3 【正确答案】 int fun( char*str) int i,n =0, fg =1; char *p=str; while( *p) /*将指针 p置位到字符串末尾,并统计字符数 */ n+; p+; for(i=0; i n/2; i+)/*循环比较字符 */ if (stri=strn 一 1一 1); /*相同,什么都不作 */ else/*不同,直接跳出循环 */ fg=0; break; return fg; 【试题解析】 判断圆文就是将第一个字符与最后一个字符比较,第二个字符与倒数第二个字符进行比较,依此类推,直到中间的字符,如果比较的结果都相同,那么这个字符串就是回文,否则不是。程序中循环语句用来遍历字符串,条件语句用来判断当前字符与对应位置的字符是否相同。

展开阅读全文
相关资源
猜你喜欢
  • BS PD ISO TS 19337-2016 Nanotechnologies Characteristics of working suspensions of nano-objects for $ii$in $iv$ii$it$ir$io assays to evaluate inherent nano-object toxi city《纳米技术 评估纳米物体固有毒性的体外试验所.pdf BS PD ISO TS 19337-2016 Nanotechnologies Characteristics of working suspensions of nano-objects for $ii$in $iv$ii$it$ir$io assays to evaluate inherent nano-object toxi city《纳米技术 评估纳米物体固有毒性的体外试验所.pdf
  • BS PD ISO TS 21219-2-2014 Intelligent transport systems Traffic and travel information (TTI) via transport protocol experts group generation 2 (TPEG2) UML modelling rules《智能运输系统 利用第二代传输协议专家组 (TPEG.pdf BS PD ISO TS 21219-2-2014 Intelligent transport systems Traffic and travel information (TTI) via transport protocol experts group generation 2 (TPEG2) UML modelling rules《智能运输系统 利用第二代传输协议专家组 (TPEG.pdf
  • BS PD ISO TS 28560-4-2014 Information and documentation RFID in libraries Encoding of data elements based on rules from ISO IEC 15962 in an RFID tag with partitioned memory《信息与文献 图书馆中应用的无线射频识别技术.pdf BS PD ISO TS 28560-4-2014 Information and documentation RFID in libraries Encoding of data elements based on rules from ISO IEC 15962 in an RFID tag with partitioned memory《信息与文献 图书馆中应用的无线射频识别技术.pdf
  • BS S 150-1975 Specification for chromium-molybdenum-vanadium-niobium heat-resisting steel billets bars forgings and parts (930-1080 MPa) (Cr 10 5 Mo 0 6 V 0 2 Nb 0 3)《铬-钼-钒-铌-耐热钢坯、棒材、锻件及零件规范(930-.pdf BS S 150-1975 Specification for chromium-molybdenum-vanadium-niobium heat-resisting steel billets bars forgings and parts (930-1080 MPa) (Cr 10 5 Mo 0 6 V 0 2 Nb 0 3)《铬-钼-钒-铌-耐热钢坯、棒材、锻件及零件规范(930-.pdf
  • BS PD ISO IEC TR 20000-12-2016 Information technology Service management Guidance on the relationship between ISO IEC 20000-1 2011 and service management frameworks CMMI-SVC 《信息技术 .pdf BS PD ISO IEC TR 20000-12-2016 Information technology Service management Guidance on the relationship between ISO IEC 20000-1 2011 and service management frameworks CMMI-SVC 《信息技术 .pdf
  • BS PD ISO IEC TR 20007-2014 Information technology Cultural and linguistic interoperability Definitions and relationship between symbols icons animated icons pictograms characters .pdf BS PD ISO IEC TR 20007-2014 Information technology Cultural and linguistic interoperability Definitions and relationship between symbols icons animated icons pictograms characters .pdf
  • BS PD ISO IEC TR 29110-5-1-3-2017 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Software engineering Management and engineering guide Generic p.pdf BS PD ISO IEC TR 29110-5-1-3-2017 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Software engineering Management and engineering guide Generic p.pdf
  • BS PD ISO IEC TR 29110-5-6-1-2015 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Systems engineering Management and engineering guide Generic pr.pdf BS PD ISO IEC TR 29110-5-6-1-2015 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Systems engineering Management and engineering guide Generic pr.pdf
  • BS PD ISO IEC TR 29110-5-6-2-2014 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Systems engineering Management and engineering guide Generic pr.pdf BS PD ISO IEC TR 29110-5-6-2-2014 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Systems engineering Management and engineering guide Generic pr.pdf
  • 相关搜索

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

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