【计算机类职业资格】二级C语言-218 (1)及答案解析.doc

上传人:priceawful190 文档编号:1325038 上传时间:2019-10-17 格式:DOC 页数:6 大小:32.50KB
下载 相关 举报
【计算机类职业资格】二级C语言-218 (1)及答案解析.doc_第1页
第1页 / 共6页
【计算机类职业资格】二级C语言-218 (1)及答案解析.doc_第2页
第2页 / 共6页
【计算机类职业资格】二级C语言-218 (1)及答案解析.doc_第3页
第3页 / 共6页
【计算机类职业资格】二级C语言-218 (1)及答案解析.doc_第4页
第4页 / 共6页
【计算机类职业资格】二级C语言-218 (1)及答案解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、二级 C 语言-218 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充函数 proc(),该函数的功能是:把字符串 str 中的字符按字符的 ASCII 码升序排列,处理后的字符串仍然保存在原串中,字符串及其长度作为函数参数传入。 例如,如果输入“gfedcba”,则输出为“abcdefg”。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #includestdlib.h #define

2、N 80 void proc(char str,int n) int i,j; char ch; for(i=0;in;i+) for(j= 1;jn;j+) if(stristrj) ch=strj; 2; stri=ch; void main() int i=0,strlen=0; char strN; system(“CLS“); printf(“/nInput a string:/n“); gets(str); while(stri!=“/0“) strlen+; i+; proc(str,strlen); printf(“/n*display string*/n“); puts(st

3、r); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:求 S 的值。 S=(2 2 /(1*3)*(4 2 /(3*5)*(6 2 /(5*7)*(2n) 2 /(2n-1)*(2n+1) 例如,当 n 为 100 时,函数的值应为 1.566893。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h #includemath.h /*found* p

4、roc(int n) int n;float sum,w,p,q; n=1; sum=1.0; while(n=n) w=2.0*n; p=w-1.0; q=w+1.0; sum=sum*w*w/p/q; n+; /*found* return sum void main() system(“CLS“); printf(“%f/n“,proc(100); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写函数 void proc(char a,charb,int n),其功能是:删除一个字符串中指定下标的字符。其中,a 指向原字符串,删除后的字符串存放在 b 所指的数

5、组中,n 中存放指定的下标。 例如,输入一个字符串 thanyou,然后输入 4,则调用该函数后的结果为 thanyou。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 fun()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includestdio.h #includeconio.h #define N 20 void proc(char a,char b,int n) void main() char str1N,str2N; int n; system(“CLS“); printf(“Enter the str

6、ing:/n“); gets(str1); printf(“Enter the position of the string deleted:“); scanf(“%d“, proc(str1,str2,n); printf(“The new string is:%s/n“,str2); (分数:40.00)_二级 C 语言-218 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充函数 proc(),该函数的功能是:把字符串 str 中的字符按字符的 ASCII 码升序排列,处理后的字符串仍然保存在原串中,字符串及其长度作为函数

7、参数传入。 例如,如果输入“gfedcba”,则输出为“abcdefg”。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #includestdlib.h #define N 80 void proc(char str,int n) int i,j; char ch; for(i=0;in;i+) for(j= 1;jn;j+) if(stristrj) ch=strj; 2; stri=ch; void main() int i=0,strlen=0; c

8、har strN; system(“CLS“); printf(“/nInput a string:/n“); gets(str); while(stri!=“/0“) strlen+; i+; proc(str,strlen); printf(“/n*display string*/n“); puts(str); (分数:30.00)解析:i+1 strj=stri解析 题目要求把字符串 str 中的字符按其 ASCII 码值升序排列,可以使字符串中的每一个字符与其后的所有字符相比较,因此第一处填“i+1”;把该字符与 ASCII 码值小于其本身而且位置在它后面的字符相交换,最后就可以使 A

9、SCII 码值小的在前、大的在后,因此第二处填“strj=stri”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:求 S 的值。 S=(2 2 /(1*3)*(4 2 /(3*5)*(6 2 /(5*7)*(2n) 2 /(2n-1)*(2n+1) 例如,当 n 为 100 时,函数的值应为 1.566893。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h #inc

10、ludemath.h /*found* proc(int n) int n;float sum,w,p,q; n=1; sum=1.0; while(n=n) w=2.0*n; p=w-1.0; q=w+1.0; sum=sum*w*w/p/q; n+; /*found* return sum void main() system(“CLS“); printf(“%f/n“,proc(100); (分数:30.00)解析:错误:proc(int n) 正确:double proc(int k) 错误:return sum 正确:return sum; 解析 由主函数中的函数调用及函数 proc

11、)中的 return 语句可知,函数 proc()的返回值类型应为 double 型,因此“proc(int k)”前面应加上 double;根据 C 语言的语法规则,每一条语句都必须以分号结束,因此语句“return s”后应加上分号。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 void proc(char a,charb,int n),其功能是:删除一个字符串中指定下标的字符。其中,a 指向原字符串,删除后的字符串存放在 b 所指的数组中,n 中存放指定的下标。 例如,输入一个字符串 thanyou,然后输入 4,则调用该函数后的结果为 thanyou。 注意:部分源程

12、序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 fun()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includestdio.h #includeconio.h #define N 20 void proc(char a,char b,int n) void main() char str1N,str2N; int n; system(“CLS“); printf(“Enter the string:/n“); gets(str1); printf(“Enter the position of the string delete

13、d:“); scanf(“%d“, proc(str1,str2,n); printf(“The new string is:%s/n“,str2); (分数:40.00)_正确答案:()解析:void proc(char a,char b,int n) int i,k=0; for(i=0;ai!=“/0“;i+)/要删除,也就是把下标不是 n 的字符放到 b 中 if(i!=n) /n 中存放指定的下标 bk+=ai; /删除指定字符后的字符串存放在 b 所指的数组中 bk=“/0“;/用“/0“作为字符串的结束标志 解析 按照题目中的要求,删除一个字符串中指定下标的字符。首先,将指定下标之前的字符放入字符数组 b 中,然后将指定下标之后的字符也放入字符数组 b 中,最后为新的字符数组 b 添加结束符。

展开阅读全文
相关资源
猜你喜欢
  • SANS 60598-2-23-2001 Luminaires Part 2-23 Particular requirements - Extra low voltage lighting systems for filament lamps《灯具 第2 23部分:特殊要求 白炽灯用超低压照明系统》.pdf SANS 60598-2-23-2001 Luminaires Part 2-23 Particular requirements - Extra low voltage lighting systems for filament lamps《灯具 第2 23部分:特殊要求 白炽灯用超低压照明系统》.pdf
  • SANS 60598-2-25-1994 Luminaires Part 2-25 Particular requirements - Luminaires for use in clinical areas of hospitals and health care buildings《灯具 第2 25部分:特殊要求 医院和医疗保健中心临床区域用灯具》.pdf SANS 60598-2-25-1994 Luminaires Part 2-25 Particular requirements - Luminaires for use in clinical areas of hospitals and health care buildings《灯具 第2 25部分:特殊要求 医院和医疗保健中心临床区域用灯具》.pdf
  • SANS 60598-2-4-1997 Luminaires Part 2 Particular requirements Section 4 Portable general purpose luminaires《灯具 第2部分:特殊要求 第4节:便携式通用灯具》.pdf SANS 60598-2-4-1997 Luminaires Part 2 Particular requirements Section 4 Portable general purpose luminaires《灯具 第2部分:特殊要求 第4节:便携式通用灯具》.pdf
  • SANS 60598-2-6-1994 Luminaires Part 2 Particular requirements Section 6 Luminaires with built-in transformers or convertors for filament lamps《灯具 第2部分:特殊要求 第6节:内装变压器的钨丝灯灯具》.pdf SANS 60598-2-6-1994 Luminaires Part 2 Particular requirements Section 6 Luminaires with built-in transformers or convertors for filament lamps《灯具 第2部分:特殊要求 第6节:内装变压器的钨丝灯灯具》.pdf
  • SANS 60598-2-7-1982 Luminaires Part 2 Particular requirements Section 7 Portable luminaires for garden use《灯具 第2部分:特殊要求 第7节:庭园用便携式灯具》.pdf SANS 60598-2-7-1982 Luminaires Part 2 Particular requirements Section 7 Portable luminaires for garden use《灯具 第2部分:特殊要求 第7节:庭园用便携式灯具》.pdf
  • SANS 60598-2-9-1987 Luminaires Part 2 Particular requirements Section 9 Photo and film luminaires (non-professional)《灯具 第2部分:特殊要求 第9节:摄像和摄影用灯具(非专业)》.pdf SANS 60598-2-9-1987 Luminaires Part 2 Particular requirements Section 9 Photo and film luminaires (non-professional)《灯具 第2部分:特殊要求 第9节:摄像和摄影用灯具(非专业)》.pdf
  • SANS 606-2006 Short-pitch transmission precision roller and bush chains attachments and associated chain sprockets《传动用短节距精密滚子链,套筒链,附件和链轮》.pdf SANS 606-2006 Short-pitch transmission precision roller and bush chains attachments and associated chain sprockets《传动用短节距精密滚子链,套筒链,附件和链轮》.pdf
  • SANS 6060-2005 Analysis of plumage fillings (hand-sorting method)《羽毛填充物的分析(手工分选法)》.pdf SANS 6060-2005 Analysis of plumage fillings (hand-sorting method)《羽毛填充物的分析(手工分选法)》.pdf
  • SANS 60601-2-2-2009 Medical electrical equipment Part 2-2 Particular requirements for the basic safety and essential performance of high frequency surgical equipment and high frequ.pdf SANS 60601-2-2-2009 Medical electrical equipment Part 2-2 Particular requirements for the basic safety and essential performance of high frequency surgical equipment and high frequ.pdf
  • 相关搜索

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

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