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

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

1、二级 C 语言-357 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充函数 proc(),该函数的功能是:按“0“到“9“统计一个字符串中的奇数数字字符各自出现的次数,结果保存在数组 num 中(注意:不能使用字符串库函数)。 例如,输入“x=15811453927843770hfds574”,结果为:1=2,3=2,5=3,7=4,9=1。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h

2、 #includestdio.h #define M 1000 void proc(char*str,int num) int i,j; int bb10; char*p=str; for(i=0;i10;i+) numi=0; bbi=0; while( 1) if(*p=“0“ p+; for(i=1,j=0;i10;i=i+2,j+) 3; void main() char strM; int num10,k; syslem(“CLS“); printf(“/nPlease enter a char string:“); gets(str); printf(“/n*The origina

3、l string*/n“); puts(str); proc(str,num); printf(“/n*The number of letter*/n“); for(k=0;k5;k+) printf(“/n“); printf(“%d=%d“,2*k+1,numk); printf(“/n“); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:判断一个整数 m 是否是素数,若是返回 1,否则返回 0。在main()函数中,若 proc()返回 1,则输出”YES”;若 proc()返回 0,则输出 NO”! 请修改程序中的错误

4、使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdio.h #includeconio.h #includestdlib.h int proc(int m) int k=2; while(k=m else return 0; void main() int n; system(“CLS“); printf(“/nPlease enter n:“); scanf(“%d“, if(proc(n)printf(“YES/n“); else printf(“NO!/n“); (分数:30.00)三、程序设计题(总题数

5、1,分数:40.00)3.请编写一个函数 proc(),它的功能是计算并输出给定整数 n 的所有因子(不包括 1 与自身)的平方和(规定 n 的值不大于 100)。 例如,主函数从键盘输入 n 的值为 50,则输出为 sum=754。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h long proc(int n) void main() int n; long sum; printf(“Input n:“); scanf(“%d“, sum=proc(n); p

6、rintf(“sum=%1d/n“,sum); (分数:40.00)_二级 C 语言-357 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充函数 proc(),该函数的功能是:按“0“到“9“统计一个字符串中的奇数数字字符各自出现的次数,结果保存在数组 num 中(注意:不能使用字符串库函数)。 例如,输入“x=15811453927843770hfds574”,结果为:1=2,3=2,5=3,7=4,9=1。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编

7、写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h #define M 1000 void proc(char*str,int num) int i,j; int bb10; char*p=str; for(i=0;i10;i+) numi=0; bbi=0; while( 1) if(*p=“0“ p+; for(i=1,j=0;i10;i=i+2,j+) 3; void main() char strM; int num10,k; syslem(“CLS“); printf(“/nPlease enter a char string:“);

8、 gets(str); printf(“/n*The original string*/n“); puts(str); proc(str,num); printf(“/n*The number of letter*/n“); for(k=0;k5;k+) printf(“/n“); printf(“%d=%d“,2*k+1,numk); printf(“/n“); (分数:30.00)解析:*p bb*p-“0“+ numj=bbi解析 由函数 proc 可知字符型指针变量 p 指向字符串 str,要统计一个字符串中的奇数数字字符各自出现的次数,需要检查字符串 str 中每一个字符,因此,第一

9、处填“*p”。数组 bb 中存放奇数数字字符各自出现的次数,每检查到一个奇数数字字符,数字相应的元素值加 1,因此,第二处填“bb*p-“0“+”。按照题目中的要求,结果保存在数组 num 中,并返回到主函数当中,因此第三处填“numj=bbi”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 proc()的功能是:判断一个整数 m 是否是素数,若是返回 1,否则返回 0。在main()函数中,若 proc()返回 1,则输出”YES”;若 proc()返回 0,则输出 NO”! 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删

10、行,也不得更改程序的结构。 试题程序: #includestdio.h #includeconio.h #includestdlib.h int proc(int m) int k=2; while(k=m else return 0; void main() int n; system(“CLS“); printf(“/nPlease enter n:“); scanf(“%d“, if(proc(n)printf(“YES/n“); else printf(“NO!/n“); (分数:30.00)解析:错误:k+ 正确:k+; 错误:if(m=k) 正确:if(m=k) 解析 根据 C 语

11、言的语法规则,每一条语句都要以分号结束,因此,要在语句“k+”之后加上分号。判断变量 m 与变量 k 是否相等应该用符号“=”,符号“=”为赋值符号,因此,“if(m=k)”应改为“if(m=k)”。三、程序设计题(总题数:1,分数:40.00)3.请编写一个函数 proc(),它的功能是计算并输出给定整数 n 的所有因子(不包括 1 与自身)的平方和(规定 n 的值不大于 100)。 例如,主函数从键盘输入 n 的值为 50,则输出为 sum=754。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程

12、序: #includestdio.h long proc(int n) void main() int n; long sum; printf(“Input n:“); scanf(“%d“, sum=proc(n); printf(“sum=%1d/n“,sum); (分数:40.00)_正确答案:()解析:long proc(int n) int i; long s=0; for(i=2;i=n-1;i+) /从 2n-1 中找出 n 的所有因子 if(n%i=0) s+=i*i; /将所有因子求平方和 return s; /将平方和返回 解析 整数 n 的因子是能够整除整数 n 的整数。题目中要求计算并输出给定整数 n 的所有因子(不包括 1 与自身)的平方和,应该判断所有大于 1 小于 n 的整数是否能够整除 n。求出所有能够整除 n 并且大于 1 小于 n 的整数的平方和。将得到的平方和返回到主函数当中。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 14437-2005 Determination of the uplift resistance of installed clay or concrete tiles for roofing - Roof system test method German version EN 14437 2004《屋顶用安装的粘土或混凝土瓦的耐隆起性的测.pdf DIN EN 14437-2005 Determination of the uplift resistance of installed clay or concrete tiles for roofing - Roof system test method German version EN 14437 2004《屋顶用安装的粘土或混凝土瓦的耐隆起性的测.pdf
  • DIN EN 14438-2007 Gas-fired insets for heating more than one room English version of DIN EN 14438 2007-03《多个房间嵌入式燃气加热装置》.pdf DIN EN 14438-2007 Gas-fired insets for heating more than one room English version of DIN EN 14438 2007-03《多个房间嵌入式燃气加热装置》.pdf
  • DIN EN 14439-2010 Cranes - Safety - Tower cranes German version EN 14439 2006+A2 2009《起重机 安全性 塔式起重机》.pdf DIN EN 14439-2010 Cranes - Safety - Tower cranes German version EN 14439 2006+A2 2009《起重机 安全性 塔式起重机》.pdf
  • DIN EN 1444-2001 Fibre-cement pipelines - Guide for laying and on-site work practices German version EN 1444 2000《纤维水泥管 敷设和现场施工指南》.pdf DIN EN 1444-2001 Fibre-cement pipelines - Guide for laying and on-site work practices German version EN 1444 2000《纤维水泥管 敷设和现场施工指南》.pdf
  • DIN EN 14444-2006 Structural adhesives - Qualitative assessment of durability of bonded assemblies - Wedge rupture test (ISO 10354 1992 modified) English version of DIN EN 14444 20.pdf DIN EN 14444-2006 Structural adhesives - Qualitative assessment of durability of bonded assemblies - Wedge rupture test (ISO 10354 1992 modified) English version of DIN EN 14444 20.pdf
  • DIN EN 14447-2005 Fibre reinforced plastics - Glass mat reinforced thermoplastics (GMT) - Determination of flowability and solidification German version of EN 14447 2005《纤维增强塑料 玻璃垫.pdf DIN EN 14447-2005 Fibre reinforced plastics - Glass mat reinforced thermoplastics (GMT) - Determination of flowability and solidification German version of EN 14447 2005《纤维增强塑料 玻璃垫.pdf
  • DIN EN 14449-2005 Glass in building - Laminated glass and laminated safety glass - Evaluation of conformity Product standard German version EN 14449 2005《建筑物玻璃 夹层玻璃和夹层安全玻璃 合格评价 产品标.pdf DIN EN 14449-2005 Glass in building - Laminated glass and laminated safety glass - Evaluation of conformity Product standard German version EN 14449 2005《建筑物玻璃 夹层玻璃和夹层安全玻璃 合格评价 产品标.pdf
  • DIN EN 14451-2005 Devices to prevent pollution by backflow of potable water - In-line anti-vacuum valves DN 8 to DN 80 - Family D type A German version EN 14451 2005《防饮用水回流污染的装置 直通.pdf DIN EN 14451-2005 Devices to prevent pollution by backflow of potable water - In-line anti-vacuum valves DN 8 to DN 80 - Family D type A German version EN 14451 2005《防饮用水回流污染的装置 直通.pdf
  • DIN EN 14452-2005 Devices to prevent pollution by backflow of potable water - Pipe interrupter with atmospheric vent and moving element DN 10 to DN 20 - Family D type B German vers.pdf DIN EN 14452-2005 Devices to prevent pollution by backflow of potable water - Pipe interrupter with atmospheric vent and moving element DN 10 to DN 20 - Family D type B German vers.pdf
  • 相关搜索

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

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