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

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

1、二级 C 语言-377 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.str 是全部由小写字母字符和空格字符组成的字符串,由 num 传入字符串的长度。请补充函数 proc(),该函数的功能是:统计字符串 str 中的单词个数,结果由变量 num 传回。每个单词之间都由空格隔开,并且字符串 str 开始不存在空格。 例如,str=“how do you do“,结果为 num=4。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序:

2、 #includestdio.h #define M 80 void proc(char*str,int*num) int i,n=0; for(i=0; 1;i+) if(stri=“a“ 3; void main() char strM; int num=0; printf(“Enter a string:/n“); gets(str); while(strnum) num+; proc(str, printf(“The number of word is: %d/n/n“,num); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()

3、的功能是:根据整型形参 n,计算如下公式的值。 A1=1,A2=1/(1+A1),A3=1/(1+A2), ,An=1/(1+A(n-1) 例如,若 n=12,则应输出 0.618026。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h /*found* int proc(int n) float A=1;int i; /*found* for(i=2;in;i+) A=1.0/(1+A); return A; vo

4、id main() int num; system(“CLS“); printf(“/nPlease enter num:“); scanf(“%d“, printf(“A%d=%1f/n“,num,proc(num); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写函数 proc(),该函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。 例如,若一维数组中的数据是: 1 1 2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10 10 删除后,数组中的内容应该是:

5、1 2 3 4 5 6 7 8 9 10 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #define M 80 int proc(int a,int n) void main() int arrM=1,1,2,2,2,3,4,4.5,6,6,6,6,7,7,8,9,9,10,10,10,10,i,n=22; printf(“The original data:/n“); for(i=0;in;i+) printf(“%3d“,arri); n=proc(arr,

6、n); printf(“/n/nYhe data after deleted :/n“); for(i=0;in;i+) printf(“%3d“,arri); printf(“/n/n“); (分数:40.00)_二级 C 语言-377 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.str 是全部由小写字母字符和空格字符组成的字符串,由 num 传入字符串的长度。请补充函数 proc(),该函数的功能是:统计字符串 str 中的单词个数,结果由变量 num 传回。每个单词之间都由空格隔开,并且字符串 str 开始不存在空格。 例如

7、str=“how do you do“,结果为 num=4。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #define M 80 void proc(char*str,int*num) int i,n=0; for(i=0; 1;i+) if(stri=“a“ 3; void main() char strM; int num=0; printf(“Enter a string:/n“); gets(str); while(strnum) num+;

8、proc(str, printf(“The number of word is: %d/n/n“,num); (分数:30.00)解析:i*num n+ *num=n解析 由主函数的 proc()函数调用可知,变量 num 中存放的是字符串 str 的字符个数,因此,第一处填“i*num”;由函数 proc()可知,变量 n 中存放字符串 str 中的字符个数,每检测到一个空格或字符串结束,单词数加 1,因此,第二处填“n+”;字符串 str 中的单词数要由形参 num 传递回主函数,因此,第三处填“*num=n”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 pro

9、c()的功能是:根据整型形参 n,计算如下公式的值。 A1=1,A2=1/(1+A1),A3=1/(1+A2), ,An=1/(1+A(n-1) 例如,若 n=12,则应输出 0.618026。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h /*found* int proc(int n) float A=1;int i; /*found* for(i=2;in;i+) A=1.0/(1+A); return A;

10、 void main() int num; system(“CLS“); printf(“/nPlease enter num:“); scanf(“%d“, printf(“A%d=%1f/n“,num,proc(num); (分数:30.00)解析:错误:int proc(int n) 正确:float proc(int n) 错误:for(i=2;in;i+) 正确:for(i=2;i=n;i+) 解析 由主函数中的调用以及函数 proc()的返回值可知,函数 proc()的返回值类型应为 float 型数据。因此,“int proc(int n)”应改为“float proc(int

11、n)”;由题目中所给公式可知,循环中应该包含 n 的值,因此,“for(i=2;in;i+)”应改为“for(i=2;i=n;i+)”。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 proc(),该函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。 例如,若一维数组中的数据是: 1 1 2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10 10 删除后,数组中的内容应该是: 1 2 3 4 5 6 7 8 9 10 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数

12、中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #define M 80 int proc(int a,int n) void main() int arrM=1,1,2,2,2,3,4,4.5,6,6,6,6,7,7,8,9,9,10,10,10,10,i,n=22; printf(“The original data:/n“); for(i=0;in;i+) printf(“%3d“,arri); n=proc(arr,n); printf(“/n/nYhe data after deleted :/n“); for(i=0;in;i+) printf(“%3d“,arri); printf(“/n/n“); (分数:40.00)_正确答案:()解析:int proc(int a,int n) int i,j=1; for(i=1;in;i+) /当其后面的数与前面的不等 if(aj-1!=ai) aj+=ai; /则其放到 a 数组中 return j; /最后把整理后的数的个数返回到主函数中 解析 题目中要求删去一维数组中所有相同的数,使之只剩一个。首先需要将字符串中的每一个字符与其后的一个字符相比较,相同则不做任何操作,不相同则将其放入新的字符串中。最后将新的字符串中的字符个数返回给主函数。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 16571-2014 Information technology - RFID privacy impact assessment process German version EN 16571 2014《信息技术 射频识别隐私影响评估过程 德文版本EN 16571-2014》.pdf DIN EN 16571-2014 Information technology - RFID privacy impact assessment process German version EN 16571 2014《信息技术 射频识别隐私影响评估过程 德文版本EN 16571-2014》.pdf
  • DIN EN 16572-2015 Conservation of cultural heritage - Glossary of technical terms concerning mortars for masonry renders and plasters used in cultural heritage German version EN 16.pdf DIN EN 16572-2015 Conservation of cultural heritage - Glossary of technical terms concerning mortars for masonry renders and plasters used in cultural heritage German version EN 16.pdf
  • DIN EN 16573-2017 Ventilation for Buildings - Performance testing of components for residential buildings - Multifunctional balanced ventilation units for single family dwellings i.pdf DIN EN 16573-2017 Ventilation for Buildings - Performance testing of components for residential buildings - Multifunctional balanced ventilation units for single family dwellings i.pdf
  • DIN EN 16575-2014 Bio-based products - Vocabulary German version EN 16575 2014《生物基质产品 词汇 德文版本EN 16575-2014》.pdf DIN EN 16575-2014 Bio-based products - Vocabulary German version EN 16575 2014《生物基质产品 词汇 德文版本EN 16575-2014》.pdf
  • DIN EN 16576-2015 Automotive fuels - Determination of manganese and iron content in diesel - Inductively coupled plasma optical emission spectrometry (ICP OES) method German versio.pdf DIN EN 16576-2015 Automotive fuels - Determination of manganese and iron content in diesel - Inductively coupled plasma optical emission spectrometry (ICP OES) method German versio.pdf
  • DIN EN 16578-2016 Ceramics sanitary appliances - Sustainability assessment German version EN 16578 2016《陶瓷卫生器具 可持续性评价 德文版本EN 16578-2016》.pdf DIN EN 16578-2016 Ceramics sanitary appliances - Sustainability assessment German version EN 16578 2016《陶瓷卫生器具 可持续性评价 德文版本EN 16578-2016》.pdf
  • DIN EN 16580-2015 Windows and doors - Wetness and splash water proof door leaves - Test and classification German version EN 16580 2015《门窗 湿度和飞溅防水门叶 试验和分类 德文版本EN 16580-2015》.pdf DIN EN 16580-2015 Windows and doors - Wetness and splash water proof door leaves - Test and classification German version EN 16580 2015《门窗 湿度和飞溅防水门叶 试验和分类 德文版本EN 16580-2015》.pdf
  • DIN EN 16581-2015 Conservation of Cultural Heritage - Surface protection for porous inorganic materials - Laboratory test methods for the evaluation of the performance of water rep.pdf DIN EN 16581-2015 Conservation of Cultural Heritage - Surface protection for porous inorganic materials - Laboratory test methods for the evaluation of the performance of water rep.pdf
  • DIN EN 16582-1-2015 Domestic swimming pools - Part 1 General requirements including safety and test methods German version EN 16582-1 2015《室内游泳池 第1部分 包括安全和试验方法在内的通用要求 德文版本EN 16582-.pdf DIN EN 16582-1-2015 Domestic swimming pools - Part 1 General requirements including safety and test methods German version EN 16582-1 2015《室内游泳池 第1部分 包括安全和试验方法在内的通用要求 德文版本EN 16582-.pdf
  • 相关搜索

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

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