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

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

1、二级 C 语言机试 37 及答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充 main 函数,该函数的功能是:从一个字符串中截取前面若干个给定长度的子字符串。其中,str1 指向原字符串,截取后的字符存放在 str2 所指的字符数组中,n 中存放需截取的字符个数。 例如:当 str1=“cdefghij”,然后输入 4,则 str2=“cdef”。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序:#includestdioh #inc

2、ludeconioh #define LEN 80 main() char str1LEN,str2LEN; int n,i; clrscr(); printf(“Enter the string:/n“); gets(str1); printf “Enter the position of the string deleted:“); scanf(U 【1】 /U); for(i=0;in;i+) U【2】 /U str2i=/0; printf(“The new string is:%s/n“,U【3】 /U); (分数:30.00)填空项 1:_二、B改错题/B(总题数:1,分数:30.

3、00)2.下列给定程序中,函数 fun()的功能是:依次取出字符串中所有的字母,形成新的字符串,并取代原字符串。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdioh #includeconioh void fun(char*S) int i,j; for(i=0,j=0;si! =/0;i+) /*found*/ if(si=A&si=Z)&(si= a&Si=z,) sj+=si; /*found*/ sj=“/0“; main() char item80; clrscr(); print

4、f(“/nEnter a string:“); gets(item); printf(“/n/nThe string is:/%s/n“,item); fun (item); printf(“/n/nThe string of changing is:/%S/n“,item); (分数:30.00)填空项 1:_三、B编程题/B(总题数:1,分数:40.00)3.下列程序定义了 NXN 的二维数组,并在主函数中自动赋值。请编写函数 fun(int aN),该函数的功能是使数组右上半三角元素中的值全部置成 0。例如 a 数组中的值为 a=4 5 6 1 7 9 3 2 6, 则返回主程序后 a

5、数组中的值应为 0 0 0 1 0 0 3 2 0 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #includeconioh #includestdioh #includestdlibh #define N 5 int fun(int a N) main() int aNN,i,j; clrscr( ); printf(“*The array*/n“); for(i=0;iN;i+) /*产生个随机的 5*5 矩阵*/ for(j=0;jN;j+) aij=rand( )%10; printf (

6、4d“,aij); printf(“/n“); fun(a); printf(“THE RESULT/n“); for(i=0;iN;i+) for(j=0;iN;j+) printf(“%4d“,aij); printf(“/n“); (分数:40.00)_二级 C 语言机试 37 答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充 main 函数,该函数的功能是:从一个字符串中截取前面若干个给定长度的子字符串。其中,str1 指向原字符串,截取后的字符存放在 str2 所指的字符数组中,n 中存放需截取的字符个数。 例如:当

7、str1=“cdefghij”,然后输入 4,则 str2=“cdef”。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序:#includestdioh #includeconioh #define LEN 80 main() char str1LEN,str2LEN; int n,i; clrscr(); printf(“Enter the string:/n“); gets(str1); printf “Enter the position of the string deleted:“);

8、 scanf(U 【1】 /U); for(i=0;in;i+) U【2】 /U str2i=/0; printf(“The new string is:%s/n“,U【3】 /U); (分数:30.00)填空项 1:_ (正确答案:1 “%d“,&n 2 str2i=str1i 3 str2)解析:解析 填空 1:本题考查对标准输入函数 scanf()的调用格式,由后面的程序可以知道,变量 n 保存了要截取的字符数,注意在 n 前面不要忘了取址符&。填空 2:截取前 n 个字符,就是将字符串str1 的前 n 个字符依次赋给字符串 str2 的前 n 个字符。填空 3:本题考查对标准输出函数

9、 printf()的调用格式,根据题意,应输出截取后的字符串,即字符串 str2。二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:依次取出字符串中所有的字母,形成新的字符串,并取代原字符串。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdioh #includeconioh void fun(char*S) int i,j; for(i=0,j=0;si! =/0;i+) /*found*/ if(si=A&si=Z)&(si= a&Si=z,)

10、sj+=si; /*found*/ sj=“/0“; main() char item80; clrscr(); printf(“/nEnter a string:“); gets(item); printf(“/n/nThe string is:/%s/n“,item); fun (item); printf(“/n/nThe string of changing is:/%S/n“,item); (分数:30.00)填空项 1:_ (正确答案:(1)错误:if(si=A&si=Z)&(si=a&si=z))解析:正确:if(si=A&si=Z)|si=a&si=z) (2) 错误:sj=“

11、/0“ 正确:sj=/0 解析 错误 1:字母包括小写字母和大写字母,这里是“或”的关系,所以用“|”运算符。错误 2:字符串的结束标志符为字符,而不是字符串。三、B编程题/B(总题数:1,分数:40.00)3.下列程序定义了 NXN 的二维数组,并在主函数中自动赋值。请编写函数 fun(int aN),该函数的功能是使数组右上半三角元素中的值全部置成 0。例如 a 数组中的值为 a=4 5 6 1 7 9 3 2 6, 则返回主程序后 a 数组中的值应为 0 0 0 1 0 0 3 2 0 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括

12、号中填入所编写的若干语句。 试题程序: #includeconioh #includestdioh #includestdlibh #define N 5 int fun(int a N) main() int aNN,i,j; clrscr( ); printf(“*The array*/n“); for(i=0;iN;i+) /*产生个随机的 5*5 矩阵*/ for(j=0;jN;j+) aij=rand( )%10; printf (“%4d“,aij); printf(“/n“); fun(a); printf(“THE RESULT/n“); for(i=0;iN;i+) for(j=0;iN;j+) printf(“%4d“,aij); printf(“/n“); (分数:40.00)_正确答案:()解析:int fun (int aN) int i,j; for(i=0;iN;i+) for(j=i;jN;j+) aij=0; /*将数组右上半三角元素中的值全部置成 0*/ 解析 本题旨在考查控制数组中右上半三角元素的算法,也就是两个千篇一律的循环语句,希望学习者能够掌握消化。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 2240-034-1996 Aerospace Series Lamps Incandescent Part 034  Lamp Code 382 Product Standard Edition P 1《航空航天系列白炽灯.第034部分 码指示灯382产品标准.P1版》.pdf AECMA PREN 2240-034-1996 Aerospace Series Lamps Incandescent Part 034 Lamp Code 382 Product Standard Edition P 1《航空航天系列白炽灯.第034部分 码指示灯382产品标准.P1版》.pdf
  • AECMA PREN 2240-035-1996 Aerospace Series Lamps Incandescent Part 035  Lamp Code 387 Product Standard Edition P 1《航空航天系列白炽灯.第035部分 码指示灯387产品标准.P1版》.pdf AECMA PREN 2240-035-1996 Aerospace Series Lamps Incandescent Part 035 Lamp Code 387 Product Standard Edition P 1《航空航天系列白炽灯.第035部分 码指示灯387产品标准.P1版》.pdf
  • AECMA PREN 2240-036-1996 Aerospace Series Lamps Incandescent Part 036  Lamp Code 388 Product Standard Edition P 1《航空航天系列白炽灯.第036部分 码指示灯388产品标准.P1版》.pdf AECMA PREN 2240-036-1996 Aerospace Series Lamps Incandescent Part 036 Lamp Code 388 Product Standard Edition P 1《航空航天系列白炽灯.第036部分 码指示灯388产品标准.P1版》.pdf
  • AECMA PREN 2240-037-1996 Aerospace Series Lamps Incandescent Part 037  Lamp Code 394 Product Standard Edition P 1《航空航天系列白炽灯.第037部分 码指示灯394产品标准.P1版》.pdf AECMA PREN 2240-037-1996 Aerospace Series Lamps Incandescent Part 037 Lamp Code 394 Product Standard Edition P 1《航空航天系列白炽灯.第037部分 码指示灯394产品标准.P1版》.pdf
  • AECMA PREN 2240-038-1996 Aerospace Series Lamps Incandescent Part 038  Lamp Code 401 Product Standard Edition P 1《航空航天系列白炽灯.第038部分 码指示灯401产品标准.P1版》.pdf AECMA PREN 2240-038-1996 Aerospace Series Lamps Incandescent Part 038 Lamp Code 401 Product Standard Edition P 1《航空航天系列白炽灯.第038部分 码指示灯401产品标准.P1版》.pdf
  • AECMA PREN 2240-039-1996 Aerospace Series Lamps Incandescent Part 039  Lamp Code 600 Product Standard Edition P 1《航空航天系列白炽灯.第039部分 码指示灯600产品标准.P1版》.pdf AECMA PREN 2240-039-1996 Aerospace Series Lamps Incandescent Part 039 Lamp Code 600 Product Standard Edition P 1《航空航天系列白炽灯.第039部分 码指示灯600产品标准.P1版》.pdf
  • AECMA PREN 2240-040-1996 Aerospace Series Lamps Incandescent Part 040  Lamp Code 680 Product Standard Edition P 1《航空航天系列白炽灯.第040部分 码指示灯680产品标准.P1版》.pdf AECMA PREN 2240-040-1996 Aerospace Series Lamps Incandescent Part 040 Lamp Code 680 Product Standard Edition P 1《航空航天系列白炽灯.第040部分 码指示灯680产品标准.P1版》.pdf
  • AECMA PREN 2240-041-1996 Aerospace Series Lamps Incandescent Part 041  Lamp Code 682 Product Standard Edition P 1《航空航天系列白炽灯.第041部分 码指示灯682产品标准.P1版》.pdf AECMA PREN 2240-041-1996 Aerospace Series Lamps Incandescent Part 041 Lamp Code 682 Product Standard Edition P 1《航空航天系列白炽灯.第041部分 码指示灯682产品标准.P1版》.pdf
  • AECMA PREN 2240-042-1996 Aerospace Series Lamps Incandescent Part 042  Lamp Code 683 Product Standard Edition P 1《航空航天系列白炽灯.第042部分 码指示灯683产品标准.P1版》.pdf AECMA PREN 2240-042-1996 Aerospace Series Lamps Incandescent Part 042 Lamp Code 683 Product Standard Edition P 1《航空航天系列白炽灯.第042部分 码指示灯683产品标准.P1版》.pdf
  • 相关搜索

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

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