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

上传人:eventdump275 文档编号:1325148 上传时间:2019-10-17 格式:DOC 页数:5 大小:31KB
下载 相关 举报
【计算机类职业资格】二级C语言-293及答案解析.doc_第1页
第1页 / 共5页
【计算机类职业资格】二级C语言-293及答案解析.doc_第2页
第2页 / 共5页
【计算机类职业资格】二级C语言-293及答案解析.doc_第3页
第3页 / 共5页
【计算机类职业资格】二级C语言-293及答案解析.doc_第4页
第4页 / 共5页
【计算机类职业资格】二级C语言-293及答案解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 C 语言-293 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:把形参 s 所指字符串中最右边的 n 个字符复制到形参 t 所指字符数组中,形成一个新串。若 s 所指字符串的长度小于 n,则将整个字符串复制到形参 t 所指字符数组中。 例如,形参 s 所指的字符串为:abcdefgh,n 的值为 5,程序执行后 t 所指字符数组中的字符串应为:defgh。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 不得增行或删行,也不得更改程序的结构! 给定源程序: #includ

2、estdio.h #includestring.h #define N 80 void fun(char *s, int n, char *t) int len, i, j=0; len=strlen(s); /*found*/ if(n=len)strepy( 1); else /*found*/ for(i=len-n; i=len-1; j+)tj+= 2; /*found*/ tj= 3; main() char sN, tN; int n; printf(“Enter a string:“); gets(s); printf(“Enter n:“); scanf(“%d“, fun(

3、s, n, t); printf(“The string t:“); puts(t); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.给定程序中函数 fun 的功能是:找出一个大于形参 m 且紧随 m 的素数,并作为函数值返回。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #includestdio.h int fun(int m) int i, k; for(i=m+1;i+) for(k=2; ki; k+) /*found*/ if(i%k!=0) break; /*found*

4、/ if(ki) return(i); void main() int n; n=fun(20); printf(“n=%d/n“, n); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写函数 fun,它的功能是:求出能整除形参 x 且不是偶数的各整数,并按从小到大的顺序放在 pp所指的数组中,这些除数的个数通过形参 n 返回。 例如,若 x 中的值为:35,则有 4 个数符合要求,它们是:1,5,7,35。 请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #includestdio.h void

5、 fun(int x, int pp, int*n) main() int x, aa1000, n, i; printf(“/Please enter an integer number:/n“); scanf(“%d“, fun(x, aa, for(i=0; in; j+) printf(“%d“, aai); printf(“/n“); (分数:40.00)_二级 C 语言-293 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.给定程序中,函数 fun 的功能是:把形参 s 所指字符串中最右边的 n 个字符复制到形参 t 所指字符

6、数组中,形成一个新串。若 s 所指字符串的长度小于 n,则将整个字符串复制到形参 t 所指字符数组中。 例如,形参 s 所指的字符串为:abcdefgh,n 的值为 5,程序执行后 t 所指字符数组中的字符串应为:defgh。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 不得增行或删行,也不得更改程序的结构! 给定源程序: #includestdio.h #includestring.h #define N 80 void fun(char *s, int n, char *t) int len, i, j=0; len=strlen(s); /*found*/ i

7、f(n=len)strepy( 1); else /*found*/ for(i=len-n; i=len-1; j+)tj+= 2; /*found*/ tj= 3; main() char sN, tN; int n; printf(“Enter a string:“); gets(s); printf(“Enter n:“); scanf(“%d“, fun(s, n, t); printf(“The string t:“); puts(t); (分数:30.00)解析:(1)t, s (2)si (3)0 或“/0“ 解析 本题是在矩阵中找出在行上最大、在列上最小的那个元素。填空 1:

8、当给定的长度 n 大于该字符串 s 的长度,那么把该字符串直接拷贝到 t 就可以了,所以应填 t, s。 填空 2:使用 for 循环语句,把最右边 n 个字符依次添加到 t 中,所以应填 si。 填空 3:字符串操作结束,需要给 t 加一个字符串结束符,所以应填 0 或“/0“。二、程序改错题(总题数:1,分数:30.00)2.给定程序中函数 fun 的功能是:找出一个大于形参 m 且紧随 m 的素数,并作为函数值返回。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #includestdio.h int f

9、un(int m) int i, k; for(i=m+1;i+) for(k=2; ki; k+) /*found*/ if(i%k!=0) break; /*found*/ if(ki) return(i); void main() int n; n=fun(20); printf(“n=%d/n“, n); (分数:30.00)解析:(1)if(i%k=0) (2)if(k=i) 解析 (1)判断当前数是否为素数,若存在一个数(除 1 和其自身)能整除当前数,则跳出本次循环,所以 if 条件应为 i%k=0。 (2)如果 i 是素数,则循环结束时 k=i,将该值返回。三、程序设计题(总题

10、数:1,分数:40.00)3.请编写函数 fun,它的功能是:求出能整除形参 x 且不是偶数的各整数,并按从小到大的顺序放在 pp所指的数组中,这些除数的个数通过形参 n 返回。 例如,若 x 中的值为:35,则有 4 个数符合要求,它们是:1,5,7,35。 请勿改动主函数 main 和其它函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 给定源程序: #includestdio.h void fun(int x, int pp, int*n) main() int x, aa1000, n, i; printf(“/Please enter an integer num

11、ber:/n“); scanf(“%d“, fun(x, aa, for(i=0; in; j+) printf(“%d“, aai); printf(“/n“); (分数:40.00)_正确答案:()解析:void fun(int x, int pp, int *n) int i, j=0; for(i=1; i=x; i=i+2)/*i 的初始值为 1,步长为 2,确保 i 为奇数*/ if(x%i=0) /*将能整除 x 的数存入数组 pp 中*/ ppj+=i; *n=j; /*传回满足条件的数的个数*/ 解析 本题考查:偶数的判定方法;整除的实现。 本题题干信息是:能整除 x 且不是偶数的所有整数。循环语句中变量 i 从 1 开始且每次增 2,所以 i 始终是奇数。整除的方法,在前面已经讲过多次,这里就不再赘述了。对于本题目要求的不是偶数的判定方法,即该数对 2 求余不为 0。除以上方法外,还可以通过 for 循环语句直接把偶数筛出去,确保参与操作的数均为奇数。

展开阅读全文
相关资源
猜你喜欢
  • DIN 38406-13-1992 German standard methods for the examination of water waste water and sludge cations (group E) determination of potassium by atomic absorption spectrometry (AAS) u.pdf DIN 38406-13-1992 German standard methods for the examination of water waste water and sludge cations (group E) determination of potassium by atomic absorption spectrometry (AAS) u.pdf
  • DIN 38406-14-1992 German standard methods for the examination of water waste water and sludge cations (group E) determination of sodium by atomic absorption spectrometry (ASS) usin.pdf DIN 38406-14-1992 German standard methods for the examination of water waste water and sludge cations (group E) determination of sodium by atomic absorption spectrometry (ASS) usin.pdf
  • DIN 38406-16-1990 German standard methods for the examination of water waste water and sludge cations (group E) determination of zinc cadmium lead copper thallium nickel cobalt by .pdf DIN 38406-16-1990 German standard methods for the examination of water waste water and sludge cations (group E) determination of zinc cadmium lead copper thallium nickel cobalt by .pdf
  • DIN 38406-17-2009 de 2868 German standard methods for the examination of water waste water and sludge - Cations (group E) - Part 17 Determination of uranium - Method using adsorpti.pdf DIN 38406-17-2009 de 2868 German standard methods for the examination of water waste water and sludge - Cations (group E) - Part 17 Determination of uranium - Method using adsorpti.pdf
  • DIN 38406-18-1990 German standard methods for the examination of water waste water and sludge cations (group E) determination of dissolved silver by atomic absorption spectrometry .pdf DIN 38406-18-1990 German standard methods for the examination of water waste water and sludge cations (group E) determination of dissolved silver by atomic absorption spectrometry .pdf
  • DIN 38406-2-1983 German standard methods for the examination of water waste water and sludge cations (group E) determination of manganese (E 2)《德国检验水、废水和污泥的标准方法 阳离子(E组) 锰的测定(E 2)》.pdf DIN 38406-2-1983 German standard methods for the examination of water waste water and sludge cations (group E) determination of manganese (E 2)《德国检验水、废水和污泥的标准方法 阳离子(E组) 锰的测定(E 2)》.pdf
  • DIN 38406-21-1980 German standard methods for the examination of water waste water and sludge cations (group E) determination of nine heavy metals (Ag Bi Cd Co Cu Ni Pb Tl Zn) (E21.pdf DIN 38406-21-1980 German standard methods for the examination of water waste water and sludge cations (group E) determination of nine heavy metals (Ag Bi Cd Co Cu Ni Pb Tl Zn) (E21.pdf
  • DIN 38406-24-1993 German standard methods for the examination of water waste water and sludge cations (group E) determination of cobalt by atomic absorption spectrometry (AAS) (E 2.pdf DIN 38406-24-1993 German standard methods for the examination of water waste water and sludge cations (group E) determination of cobalt by atomic absorption spectrometry (AAS) (E 2.pdf
  • DIN 38406-26-1997 en 2667 German standard methods for the examination of water waste water and sludge - Cations (group E) - Part 26 Determination of thallium by atomic absorption s.pdf DIN 38406-26-1997 en 2667 German standard methods for the examination of water waste water and sludge - Cations (group E) - Part 26 Determination of thallium by atomic absorption s.pdf
  • 相关搜索

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

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