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

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

1、二级 C 语言-351 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:求出形参 ss 所指字符串数组中最长字符串的长度,其余字符串左边用字符*补齐,使其与最长的字符串等长。字符串数组中共有 M 个字符串,且串长小于 N。 请在程序的下划线处填入正确的内容,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h #includestring.h #define M 5 #define N 20 void fun(char(*

2、ss)N) int i,j,k=0,n,m,len; for(i=0;iM;i+) len=strlen(ssi); if(i=0)n=len; if(lenn) /*found*/ n=len; 1=i; for(i=0;iM;i+) if(i!=k) m=n; len=strlen(ssi); /*found*/ for(j= 2;j=0;j-) ssim-=ssij; for(j=0;jn-len;j+) /*found*/ 3=“*“; main() char ssMN=“shanghai“,“guangzhou“,“beijing“,“tianjin“,“chongqing“; in

3、t i; printf(“/nThe original strings are:/n“); for(i=0;iM;i+) printf(“%s“,ssi); printf(“/n“); fun(ss); printf(“/nThe result:/n“); for(i=0;iM;i+) printf(“%s“,ssi); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:计算整数 n 的阶乘。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行, 也不得更改程序的结构。 试题程序: #inclu

4、destdlib.h #includestdio.h double fun(int n) double result=1.0; while(n1 /*found*/ return; void main() int n; system(“CLS“); printf(“Enter an integer:“); scanf(“%d“, printf(“/n/n%d!=%ld/n/n“,n,fun(n); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.编写函数 fun,其功能是:从字符串中删除指定的字符。同字母的大、小写按不同字符处理。 例如,若程序执行时输入字符串为: “tu

5、rbo c and borland c+” 从键盘上输入字符 n,则输出为: “turbo c ad borlad c+” 如果输入的字符在字符串中不存在,则字符串照原样输出。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 试题程序: #includestdio.h #includestring.h void fun(char s,int c) main() static char str=“turbo c and borland c+“; char ch; printf(“原始字符串:%s/n“,str);

6、printf(“输入一个字符:“); scanf(“%c“, fun(str,ch); printf(“str=%s/n“,str); strcpy (str,“turbo c and borland c+“); fun(str,“a“); (分数:40.00)_二级 C 语言-351 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:求出形参 ss 所指字符串数组中最长字符串的长度,其余字符串左边用字符*补齐,使其与最长的字符串等长。字符串数组中共有 M 个字符串,且串长小于 N。 请在程序的下划线处填入

7、正确的内容,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h #includestring.h #define M 5 #define N 20 void fun(char(*ss)N) int i,j,k=0,n,m,len; for(i=0;iM;i+) len=strlen(ssi); if(i=0)n=len; if(lenn) /*found*/ n=len; 1=i; for(i=0;iM;i+) if(i!=k) m=n; len=strlen(ssi); /*found*/ for(j= 2;

8、j=0;j-) ssim-=ssij; for(j=0;jn-len;j+) /*found*/ 3=“*“; main() char ssMN=“shanghai“,“guangzhou“,“beijing“,“tianjin“,“chongqing“; int i; printf(“/nThe original strings are:/n“); for(i=0;iM;i+) printf(“%s“,ssi); printf(“/n“); fun(ss); printf(“/nThe result:/n“); for(i=0;iM;i+) printf(“%s“,ssi); (分数:30.

9、00)解析:(1)k (2)len (3)ssij 解析 填空 1:使用变量 k 来保存第几个字符串是最长的字符串,所以应填 k。 填空 2:利用 for 循环把原字符串右移至最右边存放,字符串的长为 len,所以应填 len。 填空 3:左边用字符*补齐,所以应填 ssij。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:计算整数 n 的阶乘。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行, 也不得更改程序的结构。 试题程序: #includestdlib.h #includestdio.h double

10、 fun(int n) double result=1.0; while(n1 /*found*/ return; void main() int n; system(“CLS“); printf(“Enter an integer:“); scanf(“%d“, printf(“/n/n%d!=%ld/n/n“,n,fun(n); (分数:30.00)解析:(1)result*=n-; (2)return result; 解析 该题采用循环语句计算 n 的阶乘。当 n 大于 1 且小于 170 时,令 result 与 n相乘,同时 n 自动减 1,循环至 n2(n1 时无须相乘)。最后将阶

11、乘的积 result 返回给主函数。三、程序设计题(总题数:1,分数:40.00)3.编写函数 fun,其功能是:从字符串中删除指定的字符。同字母的大、小写按不同字符处理。 例如,若程序执行时输入字符串为: “turbo c and borland c+” 从键盘上输入字符 n,则输出为: “turbo c ad borlad c+” 如果输入的字符在字符串中不存在,则字符串照原样输出。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 试题程序: #includestdio.h #includestring.h

12、void fun(char s,int c) main() static char str=“turbo c and borland c+“; char ch; printf(“原始字符串:%s/n“,str); printf(“输入一个字符:“); scanf(“%c“, fun(str,ch); printf(“str=%s/n“,str); strcpy (str,“turbo c and borland c+“); fun(str,“a“); (分数:40.00)_正确答案:()解析:void fun( char s,int c) int i=0; char *p; p=s; while(*p) /*判断是否为结束符*/ if(*p!=c) /*判断字符串中字符是否与指定字符相同*/ si=*p; /*不同将重新组合字符串,*/ i+; p+; /*相同则处理下一个字符。*/ si=“/0“; 解析 删除字符串中指定字符只需把未删除字符保留。该程序先将字符串 s 的首地址赋给了指针 p,经过判断后,将重新组合的字符存入 s。

展开阅读全文
相关资源
猜你喜欢
  • ETSI GSM 02 07-1994 European Digital Cellular Telecommunications System (Phase 2) Mobile Stations (MS) Features (PRETS 300 505 Version 4 7 0)《欧洲数字蜂窝通信系统(第2阶段) 移动台(MS)特征GSM300 505 版.pdf ETSI GSM 02 07-1994 European Digital Cellular Telecommunications System (Phase 2) Mobile Stations (MS) Features (PRETS 300 505 Version 4 7 0)《欧洲数字蜂窝通信系统(第2阶段) 移动台(MS)特征GSM300 505 版.pdf
  • ETSI GSM 02 07-1996 Digital Cellular Telecommunications System (Phase 2+) Mobile Stations (MS) Features《数字蜂窝通信系统(第2+阶段) 移动台(MS)特征(版本5 1 0)》.pdf ETSI GSM 02 07-1996 Digital Cellular Telecommunications System (Phase 2+) Mobile Stations (MS) Features《数字蜂窝通信系统(第2+阶段) 移动台(MS)特征(版本5 1 0)》.pdf
  • ETSI GSM 02 09-1992 European Digital Cellular Telecommunication System (Phase 1) Security Aspects《欧洲数字蜂窝通信系统(第1阶段) 安全方面》.pdf ETSI GSM 02 09-1992 European Digital Cellular Telecommunication System (Phase 1) Security Aspects《欧洲数字蜂窝通信系统(第1阶段) 安全方面》.pdf
  • ETSI GSM 02 09-1993 European Digital Cellular Telecommunication System (Phase 2) Security Aspects (ETS 300 506 Version 4 3 0)《欧洲数字蜂窝通信系统(第2阶段) 安全方面(ETS 300 506 版本4 3 0)》.pdf ETSI GSM 02 09-1993 European Digital Cellular Telecommunication System (Phase 2) Security Aspects (ETS 300 506 Version 4 3 0)《欧洲数字蜂窝通信系统(第2阶段) 安全方面(ETS 300 506 版本4 3 0)》.pdf
  • ETSI GSM 02 10-1992 European Digital Cellular Telecommunication System (Phase 1) Provision of Telecommunication Services《欧洲数字蜂窝通信系统(第1阶段) 电信业务的提供》.pdf ETSI GSM 02 10-1992 European Digital Cellular Telecommunication System (Phase 1) Provision of Telecommunication Services《欧洲数字蜂窝通信系统(第1阶段) 电信业务的提供》.pdf
  • ETSI GSM 02 11-1992 Service Accessibility《业务可接入性(版本3 7 0)》.pdf ETSI GSM 02 11-1992 Service Accessibility《业务可接入性(版本3 7 0)》.pdf
  • ETSI GSM 02 11-1993 European Digital Cellular Telecommunication System (Phase 2) Service Accessibility (PRETS 300 507 Version 4 7 0)《欧洲数字蜂窝通信系统(第2阶段) 业务可接入性(PRETS 300 507 版本4 7 0)》.pdf ETSI GSM 02 11-1993 European Digital Cellular Telecommunication System (Phase 2) Service Accessibility (PRETS 300 507 Version 4 7 0)《欧洲数字蜂窝通信系统(第2阶段) 业务可接入性(PRETS 300 507 版本4 7 0)》.pdf
  • ETSI GSM 02 11-DCS-1992 European Digital Cellular Telecommunication System (Phase 1) Service Accessibility《欧洲数字蜂窝通信系统 (第1阶段) 业务可接入性》.pdf ETSI GSM 02 11-DCS-1992 European Digital Cellular Telecommunication System (Phase 1) Service Accessibility《欧洲数字蜂窝通信系统 (第1阶段) 业务可接入性》.pdf
  • ETSI GSM 02 12-1992 European Digital Cellular Telecommunication System (Phase 1) Licensing《欧洲数字蜂窝通信系统(第1阶段) 授权》.pdf ETSI GSM 02 12-1992 European Digital Cellular Telecommunication System (Phase 1) Licensing《欧洲数字蜂窝通信系统(第1阶段) 授权》.pdf
  • 相关搜索

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

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