【计算机类职业资格】二级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 中元素的个数返回到主函数当中。

展开阅读全文
相关资源
猜你喜欢
  • GOST 30441-1997 Short link chain for lifting purposes non - calibrated grade T(8) Specifications《起重用非定标8级短环链。技术条件》.pdf GOST 30441-1997 Short link chain for lifting purposes non - calibrated grade T(8) Specifications《起重用非定标8级短环链。技术条件》.pdf
  • GOST 30442-1997 Roller transmission chains for cycles Specifications《自行车传动磙子链 技术条件》.pdf GOST 30442-1997 Roller transmission chains for cycles Specifications《自行车传动磙子链 技术条件》.pdf
  • GOST 30443-1997 Technological faundry equipment Methods of control and estimation of safety《铸造生产用工艺设备 安全性检验与评定方法》.pdf GOST 30443-1997 Technological faundry equipment Methods of control and estimation of safety《铸造生产用工艺设备 安全性检验与评定方法》.pdf
  • GOST 30444-1997 Building materials Spread flame test method《建筑材料 火焰传播试验法》.pdf GOST 30444-1997 Building materials Spread flame test method《建筑材料 火焰传播试验法》.pdf
  • GOST 30456-1997 Metal production Rolled steel and tubes Methods of blow bending tests《金属制品 钢板轧材与钢管 冲击弯曲试验方法》.pdf GOST 30456-1997 Metal production Rolled steel and tubes Methods of blow bending tests《金属制品 钢板轧材与钢管 冲击弯曲试验方法》.pdf
  • GOST 30457 3-2006 Acoustics Determination of sound power levels of noise sources using sound intensity Part 3 Precision method for measurement by scanning《声学 利用声音强度测定噪声源功率级 第3部分 扫描.pdf GOST 30457 3-2006 Acoustics Determination of sound power levels of noise sources using sound intensity Part 3 Precision method for measurement by scanning《声学 利用声音强度测定噪声源功率级 第3部分 扫描.pdf
  • GOST 30457-1997 Acoustics Determination of sound power levels of noise sources using sound intensity Measurement at discrete points Engineering method《声学 根据声强测定噪声源的声功率级 离散点的测量 工程法》.pdf GOST 30457-1997 Acoustics Determination of sound power levels of noise sources using sound intensity Measurement at discrete points Engineering method《声学 根据声强测定噪声源的声功率级 离散点的测量 工程法》.pdf
  • GOST 30459-2008 Admixtures for concretes and mortars Determination and estimate of the efficiency《混凝土和砂浆混合物 效率测定和评估》.pdf GOST 30459-2008 Admixtures for concretes and mortars Determination and estimate of the efficiency《混凝土和砂浆混合物 效率测定和评估》.pdf
  • GOST 30465-1997 Hard water to be used for testing the performance of some household electrical appliances General technical requirements《家用电器设备试验用硬水 一般技术条件》.pdf GOST 30465-1997 Hard water to be used for testing the performance of some household electrical appliances General technical requirements《家用电器设备试验用硬水 一般技术条件》.pdf
  • 相关搜索

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

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