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

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

1、二级 C 语言-216 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:从键盘输入一个字符串并保存在字符 str1 中,把字符串 str1中下标为偶数的字符保存在字符串 str2 中并输出。例如,当 str1=“computer“,则 str2=“cmue“。 注意:部分源程序给出如下。 请勿改动函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h #includeconio.h #define LEN 80

2、 void main() char str1LEN,str2LEN; char*p1=str1,*p2=str2; int i=0,j=0; system(“CLS“); printf(“Enter the string:/n“); scanf( 1); printf(“*the origial string*/n“); while(*(p1+j) printf(“ 2“,*(p1+j); j+; for(i=0;ij;i+=2) *p2+=*(str1+i); *p2=“/0“; printf(“/nThe new string is:%s/n“, 3); (分数:30.00)二、程序改错题

3、总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:通过某种方式实现两个变量值的交换,规定不允许增加语句和表达式。例如变量 num1 中的值原为 2,num2 中的值原为 1,程序运行后 num1 中的值为 1,num2 中的值为 2。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h int proc(int*x,int y) int t; /*found* t=x; *x=y; /*fo

4、und* return(y); void main() int num1=2,num2=1; system(“CLS“); printf(“%d%d/n“,num1,num2); num2=proc( printf(“%d%d/n“,num1,num2); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.下列程序定义了 MM 的二维数组,并在主函数中自动赋值。请编写函数 fun(int arrM),该函数的功能是使数组左下半三角元素中的值全部置成 0。例如,arr 数组中的值为: 1 2 3 arr=4 5 6 7 8 9 则返回主程序后 arr 数组中的值应为: 0 2

5、 3 arr=0 0 6 0 0 0 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includeconio.h #includestdio.h #includestdlib.h #includetime.h #define M 5 void proc(int arrM) void main() int arrMM,i,j; system(“CLS“); printf(“*The array*/n“); stand(unsigned)time(NULL); for(i=0;iM;i+) /产生

6、一个随机的 5*5 矩阵 for(j=0;jM;j+) arrij=rand()%10; printf(“%4d“,arrij); printf(“/n“); proc(arr); printf(“THE RESULT/n“); for(i=0;iM;i+) for(j=0;jM;j+) printf(“%4d“,arrij); printf(“/n“); (分数:40.00)_二级 C 语言-216 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:从键盘输入一个字符串并保存在字符 str1

7、中,把字符串 str1中下标为偶数的字符保存在字符串 str2 中并输出。例如,当 str1=“computer“,则 str2=“cmue“。 注意:部分源程序给出如下。 请勿改动函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h #includeconio.h #define LEN 80 void main() char str1LEN,str2LEN; char*p1=str1,*p2=str2; int i=0,j=0; system(“CLS“); printf(“Enter the string

8、/n“); scanf( 1); printf(“*the origial string*/n“); while(*(p1+j) printf(“ 2“,*(p1+j); j+; for(i=0;ij;i+=2) *p2+=*(str1+i); *p2=“/0“; printf(“/nThe new string is:%s/n“, 3); (分数:30.00)解析:“%s“,str1 %c str2解析 由程序可知,目标字符串 str2 是原始字符串 str1 中下标为偶数的字符的组合。要得到目标字符串 str2,首先要输入原始字符串 str1,因此第一处填“”%s”,str1”;第二处是

9、一个格式化的输出,str1 为字符型,因此第二处填“%c”;最后是要输出目标字符串,而目标字符串放在 str2 中,因此第三处填“str2”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:通过某种方式实现两个变量值的交换,规定不允许增加语句和表达式。例如变量 num1 中的值原为 2,num2 中的值原为 1,程序运行后 num1 中的值为 1,num2 中的值为 2。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includ

10、econio.h #includestdio.h int proc(int*x,int y) int t; /*found* t=x; *x=y; /*found* return(y); void main() int num1=2,num2=1; system(“CLS“); printf(“%d%d/n“,num1,num2); num2=proc( printf(“%d%d/n“,num1,num2); (分数:30.00)解析:错误:t=x 正确:t=*x 错误:return(y) 正确:return(t) 解析 由函数 proc()可知,变量 x 是整型指针变量,而变量 t 是整型变

11、量,不能直接赋值,因此“t=x”应改为“t=*x”;题目要求实现两个数互换,因此函数 proc()应返回变量 x 的值,而变量 x 的值存放在变量 t 中,因此“return(y)”应改为“return(t)”。三、程序设计题(总题数:1,分数:40.00)3.下列程序定义了 MM 的二维数组,并在主函数中自动赋值。请编写函数 fun(int arrM),该函数的功能是使数组左下半三角元素中的值全部置成 0。例如,arr 数组中的值为: 1 2 3 arr=4 5 6 7 8 9 则返回主程序后 arr 数组中的值应为: 0 2 3 arr=0 0 6 0 0 0 注意:部分源程序给出如下。

12、请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includeconio.h #includestdio.h #includestdlib.h #includetime.h #define M 5 void proc(int arrM) void main() int arrMM,i,j; system(“CLS“); printf(“*The array*/n“); stand(unsigned)time(NULL); for(i=0;iM;i+) /产生一个随机的 5*5 矩阵 for(j=0;jM;j+) arrij

13、rand()%10; printf(“%4d“,arrij); printf(“/n“); proc(arr); printf(“THE RESULT/n“); for(i=0;iM;i+) for(j=0;jM;j+) printf(“%4d“,arrij); printf(“/n“); (分数:40.00)_正确答案:()解析:void proc(int arrM) int i,j; for(i=0;iM;i+) /i 是控制行下标的 for(j=0;j=i;j+) /左下半三角是从下标为 0 开始的 arrij=0;/把是左下半三角的数用 0 来代替 解析 题目中要求使数组左下半三角元素中的值全部置成 0。首先要找到数组左下半三角元素,然后将其值置为 0。二维数组左下半三角元素的特点为,行下标大于等于列下标。根据此特点找出二维数组中所有的左下半三角元素,最后将这些位置上的元素均置为 0。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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