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

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

1、国家二级 C语言机试(操作题)模拟试卷 28及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为: 2、 4、 6、 8、 10,逆置后,从头至尾结点数据域依次为:10、 8、 6、 4、 2。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANKl C中。 不得增行或删行,也不得更改程序的结构 ! #include #include #define N 5 typedef struct node int data; struCt node *next;

2、NODE ; void fun(NODE *h) NODE *P, *q, *r; /*found*/ P=h一 _1_; /*found*/ if(p=_2_)return; q=P一 next; P一 next=NULL; while(q) r=q一 next ; q一 next=P; /*found*/ P=q; q=_3_; h一 next=P; NODE * creatlist(int a) NODE *h, *P, *q; int i; h=(NODE*)malloc(sizeof(NODE); h一 next=NULL; for(i=0; idata=ai; q一 next=NU

3、LL; if(h一 next=NULL)h一 next= p=q; else P一 next=q; P=q; ) return h; void outlist(NODE *h) NODE *P; P=h一 next; if(p=NULL)printf(“The list is NULL! n”); else printf(“ nHead”); do printf(“一 d”, P一 data); P=p 一 next; while(p!=NULL); printf(“一 End n”); main() NODE*head; int aN=2, 4, 6, 8, 10; heact=creatl

4、ist(a); printf(“ nThe original list: n”); outlist(head); fun(head); printf(“ nThe list after inverting: n”); outlist(head); 二、程 序修改题 2 给定程序 MODll C中函数 fun的功能是;求出两个非零正整数的最大公约数,并作为函数值返回。 例如,若给 num1和 num2分别输入 49和 21,则输出的最大公约数为 7:若给numl和 num2分别输入 27和 81,则输出的最大公约数为 27。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动 main函数

5、不得增行或删行,也不得更改程序的结构。 #include int fun(int a, int b) int r, t; if(a #include void fun(char *tt, int PP) main() char aa1000; int bb26, k; void NONO(); printf(“ nPlease enter a char string: ”); scanf(“ s“, aa); fun(aa, bb); for(k=0; k_1_; ”对结点 p进行初始化,由审题分析可知, p初始化为链表的第二个结点,即 p一 next,故第一空处应为 “next”。 第二空

6、 “if(p=_2_)return; ”如果链表只有一个结点,无需逆置,即第二空处为 “0”或 “ 0”或 “NULL”。 第三空:循环内完成结点的指针指向前一个结点, “r=q-next; ”r已经指向 q的下一个结点, “q一 next=p; ”将 q结点指向链表的前一个结点, “p=q; ”是将 p结点往后移动一个结点位置,第三空处是 q结点往后移动一个结点位置,即第三空处为 “r”。 二、程序修改题 2 【正确答案】 (1)t=a; a=b; b=t; (2)return(b); 【试题解析】 函数的功能是求出两个非零正整数的最大公约数。 (1)根据算法分析,首先要确保 a、 b两个

7、数中 a是较大数, b是较小数,如果不是,则交换 a和 b。但是第一个标识下,交换 a和 b两个数的算法有误,所以应将“t=a; b=a: a=t; ”改 为 “t=a; a=b; b=t; ”。 (2)算法到循环结束,最后余数为 0的时候, b中所存的数即为最大公约数,也就是函数要返回的值。因此,第二个标识下面的 “return(a); ”改为 “retum(b); ”。 三、程序设计题 3 【正确答案】 char *p=tt; int i; for(i=0; i=a *p=z)PP*p一 a+=1, p+; 【试题解析】 该程序功能是统计字符串中 26个字母各自出现的次数。解题思路,从已给部分源程序的 main主函数开始入手,函数形参指针 tt接受主函数中字符数组 aa的起始地址,形参 pp接受主函数中的 bb数组的起始地址, bb数组的每一个元素都是计数器, bb0中统计字母 “a”的个数, bb1中统计字母 “b”的个数,依此类推, bb25中统计字母 “z”的个数。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 2771-1988 Aerospace Series Steel FE-PL53S Hardened and Tempered 1100 Less Than or Equal to Rm Less Than or Equal to 1250 MPa Bar De Less Than or Equal to 110mm Issue P 1.pdf AECMA PREN 2771-1988 Aerospace Series Steel FE-PL53S Hardened and Tempered 1100 Less Than or Equal to Rm Less Than or Equal to 1250 MPa Bar De Less Than or Equal to 110mm Issue P 1.pdf
  • AECMA PREN 2772-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4)Air Melted Solution Treated and Precipitation Treated Forgings a or D Less Than or Equal to 200 mm Rm Greater Th.pdf AECMA PREN 2772-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4)Air Melted Solution Treated and Precipitation Treated Forgings a or D Less Than or Equal to 200 mm Rm Greater Th.pdf
  • AECMA PREN 2773-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4) Consumable Electrode Remelted Solution Treated and Precipitation Treated Sheet and Strip a Less Than or Equal tt.pdf AECMA PREN 2773-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4) Consumable Electrode Remelted Solution Treated and Precipitation Treated Sheet and Strip a Less Than or Equal tt.pdf
  • AECMA PREN 2774-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4) Consumable Electrode Remelted Solution Treated and Precipitation Treated Bar a or D Less Than or Equal to 200 mP.pdf AECMA PREN 2774-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4) Consumable Electrode Remelted Solution Treated and Precipitation Treated Bar a or D Less Than or Equal to 200 mP.pdf
  • AECMA PREN 2775-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4) Consumable Electrode Remelted Solution treated and Precipitation Treated Forgings a or D Less Than of Equal to t.pdf AECMA PREN 2775-1999 Aerospace Series Steel FE-PM3801 (X5CrNiCu17-4) Consumable Electrode Remelted Solution treated and Precipitation Treated Forgings a or D Less Than of Equal to t.pdf
  • AECMA PREN 2776-1986 Aerospace Series Steel FE-P11 Rm Less Than or Equal to 340 MPa Sheet and Strip a Less Than or Equal to 2 mm Issue P 1《航空和航天系列钢FE-P11 a Rm小于或等于340MPa 片和带 a小于或等于.pdf AECMA PREN 2776-1986 Aerospace Series Steel FE-P11 Rm Less Than or Equal to 340 MPa Sheet and Strip a Less Than or Equal to 2 mm Issue P 1《航空和航天系列钢FE-P11 a Rm小于或等于340MPa 片和带 a小于或等于.pdf
  • AECMA PREN 2779-1988 Aerospace Series Steel FE-PL56 Hardened and Tempered 1250 Less Than or Equal to Rm Less Than or Equal to 1400 MPa Bar De Less Than or Equal to 70 mm Issue P 1《.pdf AECMA PREN 2779-1988 Aerospace Series Steel FE-PL56 Hardened and Tempered 1250 Less Than or Equal to Rm Less Than or Equal to 1400 MPa Bar De Less Than or Equal to 70 mm Issue P 1《.pdf
  • AECMA PREN 2780-1988 Aerospace Series Steel FE-PL56 Hardened and Tempered 1250 Less Than or Equal to Rm Less Than or Equal to 1400 MPa Forgings De Less Than or Equal to 70 mm Issue.pdf AECMA PREN 2780-1988 Aerospace Series Steel FE-PL56 Hardened and Tempered 1250 Less Than or Equal to Rm Less Than or Equal to 1400 MPa Forgings De Less Than or Equal to 70 mm Issue.pdf
  • AECMA PREN 2781-1997 Aerospace Series Non-Metallic Materials Structural Adhesives Test Methods Determination of the Primer Thickness《航空和航天系列雷管厚度非金属物质结构黏合试验方法》.pdf AECMA PREN 2781-1997 Aerospace Series Non-Metallic Materials Structural Adhesives Test Methods Determination of the Primer Thickness《航空和航天系列雷管厚度非金属物质结构黏合试验方法》.pdf
  • 相关搜索

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

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