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

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

1、二级 C 语言-346 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:从键盘输入两个字符串并分别保存在字符数组 str1 和 str2 中,用字符串 str2 替换字符串 str1 前面的所有字符,且 str2 的长度不大于 str1,否则需要重新输入。 例如,如果输入 str1=“abcdefg“,str2=“hij“,则输出“hijdefg“。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试

2、题程序: #includestdlib.h #includestdio.h #includestring.h void main() char str181,str281; char*p1=str1,*p2=str2; system(“CLS“); do printf(“Input str1/n“); gets(str1); printf(“Input str2/n“); gets(str2); while( 1); while( 2) *p1+=*p2+; printf(“Display str1/n“); puts( 3); (分数:30.00)二、程序改错题(总题数:1,分数:30.00

3、)2.下列给定程序中,函数 proc()的功能是:用下面的公式求 的近似值,直到最后一项的绝对值小于指定的数(参数 num)为止。 /41-1/3+1/5-1/7+ 例如,程序运行后,输入 0.0001,则程序输出 3.1414。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includemath.h #includestdio.h float proc(float num) int s; float n,t,pi; t=1;pi=0;n=1;s=1; /*found* w

4、hile(t=num) pi=pi+t; n=n+2; s=-s; /*found* t=s%n; pi=pi*4; return pi; void main() float n1,n2; system(“CLS“); printf(“Enter a float number:“); scanf(“%f“, n2=proc(n1); printf(“%6.4f/n“,n2); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.编写函数 void proc(int x,int pp,int*n),它的功能是求出能整除 x 且不是奇数的各整数,并按从小到大的顺序放在 pp 所指

5、的数组中,这些除数的个数通过形参 n 返回。 例如,若 x 中的值为 30,则有 4 个数符合要求,它们是 26 10 30。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includeconio.h #includestdio.h #includestdlib.h void proc(int x,int pp,int*n) void main() int x,arr1000,n,i; system(“CLS“); printf(“/nPlease enter an integer numb

6、er:/n“); scanf(“%d“, proc(x,arr. for(i=0;in;i+) printf(“%d“,arri); printf(“/n“); (分数:40.00)_二级 C 语言-346 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:从键盘输入两个字符串并分别保存在字符数组 str1 和 str2 中,用字符串 str2 替换字符串 str1 前面的所有字符,且 str2 的长度不大于 str1,否则需要重新输入。 例如,如果输入 str1=“abcdefg“,str2=

7、hij“,则输出“hijdefg“。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在 main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h #includestring.h void main() char str181,str281; char*p1=str1,*p2=str2; system(“CLS“); do printf(“Input str1/n“); gets(str1); printf(“Input str2/n“); gets(str2); while( 1)

8、 while( 2) *p1+=*p2+; printf(“Display str1/n“); puts( 3); (分数:30.00)解析:strlen(str1)strlen(str2) *p2 str1解析 按照题目中要求,用字符串 str2 替换字符串 str1前面的所有字符的条件为:str2 的长度不大于 str1 的长度。因此,第一处填“strlen(str1)strlen(str2)”。当 str2 不结束时,将 str2 中的每一个字符替换 str1 前面的所有字符。因此,第二处填“*p2”。由程序可知,结果字符串存放在变量 str1 中。因此,第三处填“str1”。二、程序

9、改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:用下面的公式求 的近似值,直到最后一项的绝对值小于指定的数(参数 num)为止。 /41-1/3+1/5-1/7+ 例如,程序运行后,输入 0.0001,则程序输出 3.1414。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includemath.h #includestdio.h float proc(float num) int s; float n,t,pi; t=1;pi=0;n

10、1;s=1; /*found* while(t=num) pi=pi+t; n=n+2; s=-s; /*found* t=s%n; pi=pi*4; return pi; void main() float n1,n2; system(“CLS“); printf(“Enter a float number:“); scanf(“%f“, n2=proc(n1); printf(“%6.4f/n“,n2); (分数:30.00)解析:错误:while(t=num) 正确:while(fabs(t)=num) 错误:t=s%n; 正确:t=s/n; 解析 按照题目中要求直到最后一项的绝对值小

11、于指定的数(参数 num)为止,取绝对值函数为 fabs。因此,“while(t=num)”应改为“while(fabs(t)=num)”;变量 t 表示的是变量 s 与变量 n 相除的结果,而不是取模。因此,“t=s%n;”应改为“t=s/n;”。三、程序设计题(总题数:1,分数:40.00)3.编写函数 void proc(int x,int pp,int*n),它的功能是求出能整除 x 且不是奇数的各整数,并按从小到大的顺序放在 pp 所指的数组中,这些除数的个数通过形参 n 返回。 例如,若 x 中的值为 30,则有 4 个数符合要求,它们是 26 10 30。 注意:部分源程序给出如

12、下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includeconio.h #includestdio.h #includestdlib.h void proc(int x,int pp,int*n) void main() int x,arr1000,n,i; system(“CLS“); printf(“/nPlease enter an integer number:/n“); scanf(“%d“, proc(x,arr. for(i=0;in;i+) printf(“%d“,arri); printf(“/n“); (分数:40.00)_正确答案:()解析:void proc(int x,int pp,int*n) int i,j=0; for(i=2;i=x;i=i+2) /i 被整除的偶数 if(x%i=0) ppj+=i; /如果成立,则把其放到 pp 所指的数组中 *n=j; /把下标放到 n 中,通过指针返回到主函数中 解析 按照题目中要求,求出能整除 x 且不是奇数的各整数。首先判断小于等于整数 x 的所有偶数是否能被 x 整除,将能被 x 整除的奇数放入数组 pp 中。最后将数组 pp 中元素的个数返回到主函数当中。

展开阅读全文
相关资源
猜你喜欢
  • NF X35-122-13-1998 Ergonomic requirements for office work with visual display terminals (VDTs) Part 13  user guidance 《具有可视显示终端(VDTS)的办公室内人类工效学要求 第13部分 用户指南》.pdf NF X35-122-13-1998 Ergonomic requirements for office work with visual display terminals (VDTs) Part 13 user guidance 《具有可视显示终端(VDTS)的办公室内人类工效学要求 第13部分 用户指南》.pdf
  • NF X35-122-14-1999 Ergonomics requirements for office work with visual display terminals (VDTs) Part 14  menu dialogues 《具有可视显示终端(VDTs)的办公室工作的人类工效学要求 第14部分 菜单对话》.pdf NF X35-122-14-1999 Ergonomics requirements for office work with visual display terminals (VDTs) Part 14 menu dialogues 《具有可视显示终端(VDTs)的办公室工作的人类工效学要求 第14部分 菜单对话》.pdf
  • NF X35-122-15-1998 Ergonomic requirements for office work with visual display terminals (VDTs) Part 15  command dialogues 《具有可视显示终端(VDTs)的办公室工作的人类工效学要求 第15部分 命令对话》.pdf NF X35-122-15-1998 Ergonomic requirements for office work with visual display terminals (VDTs) Part 15 command dialogues 《具有可视显示终端(VDTs)的办公室工作的人类工效学要求 第15部分 命令对话》.pdf
  • NF X35-122-2-1993 Ergonomic requirements for office work with visual display terminals (vdts) Part 2  guidance on task requirements 《具有可视显示终端(VDTs)的办公室工作的人类工效学要求 第2部分 工作任务要求指南》.pdf NF X35-122-2-1993 Ergonomic requirements for office work with visual display terminals (vdts) Part 2 guidance on task requirements 《具有可视显示终端(VDTs)的办公室工作的人类工效学要求 第2部分 工作任务要求指南》.pdf
  • NF X35-122-4-1998 Ergonomic requirements for office work with visual display terminals (VDTs) Part 4  keyboard requirements 《带可视显示终端(VDTs)的办公室人类工效学要求 第4部分 键盘要求》.pdf NF X35-122-4-1998 Ergonomic requirements for office work with visual display terminals (VDTs) Part 4 keyboard requirements 《带可视显示终端(VDTs)的办公室人类工效学要求 第4部分 键盘要求》.pdf
  • NF X35-122-5-1999 Ergonomic requirements for office work with visual display terminals (VDTs) Part 5  workstation layout and postural requirements 《带可视显示终端(VDTs)的办公室工作人类工效学要求 第5部分 .pdf NF X35-122-5-1999 Ergonomic requirements for office work with visual display terminals (VDTs) Part 5 workstation layout and postural requirements 《带可视显示终端(VDTs)的办公室工作人类工效学要求 第5部分 .pdf
  • NF X35-500-1985 Working place - Integration of disabled persons - Workshop working places-requirements for the design of working places on cutting machines for the integration of d.pdf NF X35-500-1985 Working place - Integration of disabled persons - Workshop working places-requirements for the design of working places on cutting machines for the integration of d.pdf
  • NF X40-001-1956 PROTECTION TERMINOLOGY 《木材防护 术语》.pdf NF X40-001-1956 PROTECTION TERMINOLOGY 《木材防护 术语》.pdf
  • NF X40-002-1983 Wood preservation Vocabulary 《木材防护 词汇》.pdf NF X40-002-1983 Wood preservation Vocabulary 《木材防护 词汇》.pdf
  • 相关搜索

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

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