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

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

1、国家二级 C语言机试(操作题)模拟试卷 71及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是用函数指针指向要调用的函数,并进行调用。规定在 2 处使 fa指向函数 n,在 3处使 fb指向函数 f2。当调用正确时,程序输出: x1=5 .000000 x2=3. 000000。 x1*x1+x1*x2=40.000000 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANKl C中。 不得增行或删行,也不 得更改程序的结构 ! #inolude double f1(double x) retuEn x*x; )

2、double f2(double x, double y) return x*y; ) double fun(double a, double b) /*found*/ _1_ (*f)(), doub2e r1, r2; /*found*/ f= _2_ ; /*point fountion f1*/ r1 =f(a); /*found*/ f= _ 3_ ; /*point fountion f2*/ r2=(*f)(a, b); return r1+r2; main() double xi=5, x2=3, r; r=fun(x1, x2); printf(“nxl= f, x2= f,

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

4、p; /*found*/ p=h; while(P) 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; idata=rand() 16; s-next=p-next; P-next=s; p=p-next; P-next=NULL; return h; outlink(NODE*h, FILE*pf) NODE*p; p=h-next; fprintf(p

5、f, ”nnTHE LIST: nn HEAD”); while(P) fprintf(pf, “- d“, p-data); p=p-next; ) fprintf(pf, “n“); outresult(int s, FILE*pf) fprintf(pf, ”nThe SLIm of even numbers : dn, s); main() NODE*head; int evirl; head=creatlink(12); head-data=, 9 0 0 0; outlink(head, stdout); even=fun(head); printf(“nTh e result:

6、n“); outresult(even, stdout); 三、程序设计题 3 请编写函数 fun,函数的功能是:判断字符串是否为回文 ?若是,函数返回 1,主函数中输出: YES;否则返回 0,主函数中输出 NO。回文是指顺读和倒读都一样的字符串。 例如,字符串 LEVEL是回文,而字符串 123312就不是回文。 注意:部分源程序在文件 PROG1 C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 #include #2nclude #define N 8 0 int fun(char。 str) main() char sN; vo

7、id NONi(); printf(“Enter a siririg: “); gets(s); printf(“nn“); puts(s); if(fun(s)printf(”YESn”); else printf(“NOn“); NONO(); void NONO() /*请在此函数内打开文件,输入测试数据,调用 fun函数,输出数据,关闭文件。 */ FILE*rf, *wf; int i ; char sN; rf=fopen(“in dat“, “r“); wf=fopen(“out dat“, “w“); for(i=0; inext; (2)p=p-next; 【试题解析】 (1

8、)根据题干中求得除了头结点之外的结点数据域中的数据值,头指针 h,工作指针 p指向头结点的下一个结点,所以第一个标识下的 “p=h; ”指向头结点应该改为指向下一个结点 “p=h-next; ”。 (2)工作指针 p,利用 p实现对链表的遍历, p表示指向链表的当前结点,所以指向下一个结点应该是 “p=p-next; ”。 三、程序设计题 3 【正确答案】 int i, n=0, flag=1; /初始设置标识位 flag=1 char*p=str; /设置工作 指针 while(*p) /取字符串大小 n+; p+; for(i=0; in/2; i+) /循环判断字符串 s是否为回文 if

9、stri=strn一 1一 i); /设置比较位 j为 n一 1一 i else /若不符合条件,标识位设为 0,跳出循环 flag=0; break; return flag; 【试题解析】 进入 fun函数,根据前面的分析:主要思路是: (1)首先用整型变量 i表示所判断的字符串中前面对应元素的下标。 i初值为 0, n是字符串的长度,通过循环来求得 n。 (2)然后,把下标为 i的字符与下标为 “n-1-i”的字符比较,如果相同, i加 1,继续进行一对一的字符比较。不断重复此过程,直到 in/2为止。在此过程中,如果下标为 i的字符与下标为 “n-1-i”的字符不相同,则可以断定字符串不是回文,立即退出函数。 (3)如果正常结束循环,就说明字符串符合回文条件。

展开阅读全文
相关资源
猜你喜欢
  • 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
  • AECMA PREN 2786-1993 Aerospace Series Electrolytic Silver Plating of Fasteners Edition P 1《航空和航天系列电解镀银扣件》.pdf AECMA PREN 2786-1993 Aerospace Series Electrolytic Silver Plating of Fasteners Edition P 1《航空和航天系列电解镀银扣件》.pdf
  • AECMA PREN 2790-1986 Aerospace Series Rod-Ends Adjustable Self-Aligning Plain Bearing with Self-Lubricating Liner and Threaded Shank Dimensions and Loads Issue P 1《航空和航天系列可调节自对准轴承线.pdf AECMA PREN 2790-1986 Aerospace Series Rod-Ends Adjustable Self-Aligning Plain Bearing with Self-Lubricating Liner and Threaded Shank Dimensions and Loads Issue P 1《航空和航天系列可调节自对准轴承线.pdf
  • AECMA PREN 2791-1986 Aerospace Series Rod-Ends Adjustable Single Fork and Threaded Shank Dimensions and Loads Issue P 1《航空和航天系列可调节 线性单叉 尺寸和负重》.pdf AECMA PREN 2791-1986 Aerospace Series Rod-Ends Adjustable Single Fork and Threaded Shank Dimensions and Loads Issue P 1《航空和航天系列可调节 线性单叉 尺寸和负重》.pdf
  • AECMA PREN 2792-1986 Aerospace Series Rod Ends Adjustable Double Fork and Threaded Shank Dimensions and Loads Issue P 1《航空和航天系列可调节线性单叉 尺寸和负重》.pdf AECMA PREN 2792-1986 Aerospace Series Rod Ends Adjustable Double Fork and Threaded Shank Dimensions and Loads Issue P 1《航空和航天系列可调节线性单叉 尺寸和负重》.pdf
  • 相关搜索

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

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