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

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

1、二级 C 语言-376 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:先以只写方式打开文件“out.dat”,再把字符串 str 中的字符保存到这个磁盘文件中。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h #includeconio.h #define M 80 void main () FILE*fp; int i=0; char ch

2、 strM=“I“m a student!“; system(“CLS“); if(fp=fopen( 1)=NULL) printf(“cannot open out.dat/n“); exit(0); while (stri) ch=stri; 2; putchar(ch); i+; 3; (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中函数 proc()的功能是计算 1/n!的值。 例如,给 n 输入,则输出 0.166667。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程

3、序: #includestdio.h #includeconio.h /*found* int proc(int n) double t=1.0; if(n=) return 1.0; while(n1 t=1/t; return t; void main() int n; printf(“Input:N:“); scanf(“%d“, printf(“/n1/%d!=%1f/n“,n,proc(n); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写函数 void proc (int x,int pp,int*n),它的功能是:求出能整除 x 且不是偶数、不为的各

4、整数,并按从大到小的顺序放在 pp 所指的数组中,这些除数的个数通过形参 n 返回。 例如,若 x 的值为 30,则有 3 个数符合要求,它们是 15,5,3。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includeconio.h #includestdio.h #includestdlib.h void proc(int x,int pp,int*n) void main() int x,arr1000,n,i; system(“CLS“); printf(“/nPlease ente

5、r an integer number:/n“); scanf(“%d“, proc(x,are, for(i=n-1;i=0;i-) printf(“%d“,arri); printf(“/n“); (分数:40.00)_二级 C 语言-376 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:先以只写方式打开文件“out.dat”,再把字符串 str 中的字符保存到这个磁盘文件中。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在横线上填入所编写的若干表达式

6、或语句。 试题程序: #includestdlib.h #includestdio.h #includeconio.h #define M 80 void main () FILE*fp; int i=0; char ch; strM=“I“m a student!“; system(“CLS“); if(fp=fopen( 1)=NULL) printf(“cannot open out.dat/n“); exit(0); while (stri) ch=stri; 2; putchar(ch); i+; 3; (分数:30.00)解析:“out.dat“,“w“ fputc(ch,fp)

7、fclose(fp)解析 题目中要求先以只写方武打开文件“out.dat”,因此,第一处填“out.dat“”,“w“”;再把字符串 str 中的字符保存到这个磁盘文件中,因此,第二处填“fputc(ch,fp)”;每次使用完文件后要将其关闭,以释放内存空间,因此,第三处填“fclose(fp)”。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中函数 proc()的功能是计算 1/n!的值。 例如,给 n 输入,则输出 0.166667。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #inclu

8、destdio.h #includeconio.h /*found* int proc(int n) double t=1.0; if(n=) return 1.0; while(n1 t=1/t; return t; void main() int n; printf(“Input:N:“); scanf(“%d“, printf(“/n1/%d!=%1f/n“,n,proc(n); (分数:30.00)解析:错误:int proc(int n) 正确:double proc(int n) 错误:t*=n+; 正确:t*=n-; 解析 由主函数中的函数调用以及函数 proc()中的返回值可知

9、函数 proc()的返回值类型为 double 型,因此,“int proc(int n)”应改为“double proc(int n)”;题目要求计算 1/n!的值,整数 n 的阶乘为整数 1 到 n 相乘,因此,“t*=n+;”应改为“t*=n-;”。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 void proc (int x,int pp,int*n),它的功能是:求出能整除 x 且不是偶数、不为的各整数,并按从大到小的顺序放在 pp 所指的数组中,这些除数的个数通过形参 n 返回。 例如,若 x 的值为 30,则有 3 个数符合要求,它们是 15,5,3。 注意:部

10、分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includeconio.h #includestdio.h #includestdlib.h void proc(int x,int pp,int*n) void main() int x,arr1000,n,i; system(“CLS“); printf(“/nPlease enter an integer number:/n“); scanf(“%d“, proc(x,are, for(i=n-1;i=0;i-) printf(“%d“,arri); printf(“/n“); (分数:40.00)_正确答案:()解析:void proc(int x,int pp,int*n) int i,j=0; for(i=3;i=x;i=i+2) if(x%i=0) ppj+=i; /如果成立,则把它放到 pp 所指的数组中 *n=j; /把下标放到 n 中,并通过指针返回到主函数中 解析 按照题目中要求,求出能整除 x 且不是偶数的各整数。首先判断小于等于整数 x 的所有奇数是否能被 x 整除,将能被 x 整除的奇数放入数组 pp 中。最后将数组 pp 中元素的个数返回到主函数中。

展开阅读全文
相关资源
猜你喜欢
  • DIN 53362-2003 Testing of plastics films and textile fabrics (excluding nonwovens) coated or not coated fabrics - Determination of stiffness in bending - Method according to Cantil.pdf DIN 53362-2003 Testing of plastics films and textile fabrics (excluding nonwovens) coated or not coated fabrics - Determination of stiffness in bending - Method according to Cantil.pdf
  • DIN 53363-2003 Testing of plastic films - Tear test using trapezoidal test specimen with incision《塑料薄膜的检验 带凹口的梯形试样的撕裂试验》.pdf DIN 53363-2003 Testing of plastic films - Tear test using trapezoidal test specimen with incision《塑料薄膜的检验 带凹口的梯形试样的撕裂试验》.pdf
  • DIN 53366-2007 Testing of plastic films and sheetings - Determination of blocking strength《塑料薄膜和膜片的测试 粘连强度的测定》.pdf DIN 53366-2007 Testing of plastic films and sheetings - Determination of blocking strength《塑料薄膜和膜片的测试 粘连强度的测定》.pdf
  • DIN 53369-1976 Testing of plastic films determination of the shrinking stress《塑料薄膜的检验 收缩应力的测定》.pdf DIN 53369-1976 Testing of plastic films determination of the shrinking stress《塑料薄膜的检验 收缩应力的测定》.pdf
  • DIN 53370-2006 Testing of plastics films - Determination of the thickness by mechanical scanning《塑料薄膜的检验 用机械手触摸法测定厚度》.pdf DIN 53370-2006 Testing of plastics films - Determination of the thickness by mechanical scanning《塑料薄膜的检验 用机械手触摸法测定厚度》.pdf
  • DIN 53377-2015 Testing of plastic films - Determination of dimensional stability《塑料薄膜的测试 尺寸稳定性的测定》.pdf DIN 53377-2015 Testing of plastic films - Determination of dimensional stability《塑料薄膜的测试 尺寸稳定性的测定》.pdf
  • DIN 53380-1-2000 Testing of plastics - Determination of gas transmissionsrate - Part 1 Volumetrical method for testing of plastic films《塑料制品试验 气体传输率的测定 第1部分 塑料薄模试验用容积测量法》.pdf DIN 53380-1-2000 Testing of plastics - Determination of gas transmissionsrate - Part 1 Volumetrical method for testing of plastic films《塑料制品试验 气体传输率的测定 第1部分 塑料薄模试验用容积测量法》.pdf
  • DIN 53380-2-2006 Testing of plastics - Determination of gas transmission rate - Part 2 Manometric method for testing of plastic films《塑料的试验 测定气体传输率 第2部分 塑料薄膜的压力计法》.pdf DIN 53380-2-2006 Testing of plastics - Determination of gas transmission rate - Part 2 Manometric method for testing of plastic films《塑料的试验 测定气体传输率 第2部分 塑料薄膜的压力计法》.pdf
  • DIN 53380-3-1998 Testing of plastics - Determination of gas transmission rate - Part 3 Oxygen-specific carrier gas method for testing of plastic films and plastics mouldings《测定塑料的气.pdf DIN 53380-3-1998 Testing of plastics - Determination of gas transmission rate - Part 3 Oxygen-specific carrier gas method for testing of plastic films and plastics mouldings《测定塑料的气.pdf
  • 相关搜索

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

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