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

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

1、二级 C 语言-307 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.下列给定程序中,请补充函数 proc(),该函数的功能是:输出数组元素中小于平均值的元素。在主函数 main()中,从键盘输入若干个数放入数组 str 中,并以 0 结束输入但不计入数组。 例如,数组中元素的值依次为 2 3 4 5 5,则程序的运行结果为 2,3。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #inclu

2、deconio.h #includestclio.h void proc( 1, int n) double sum=0.0; double average=0.0; int i=0; for(i=0; in; i+) 2; average= 3; for(i=0; in; i+) if(xiaverage) if(i%5=0) printf(“/n“); printf(“%d, “, xi); void main() int str1000; int i=0; system(“CLS“); printf(“/nPlease enter some data(endwith 0):“); do

3、scanf(“%d“, while(stri+!=0); proc(str, i-1); (分数:30.00)二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中,函数 proc()的功能是:输出 M 行 M 列整数方阵,然后求两条对角线上的各元素之和并将其返回。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行。也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h #define M 5 /*found* int proc(int n, int xx) in

4、t i, j, sum=0; printf(“/nThe%d x%d matrix:/n“, M, M); for(i=0; iM; i+) for(j=0; jM; j+) /*found* printf(“%4f“, xxij); printf(“/n“); for(i=0; in; i+) sum+=xxii+xxin-i-1; return(sum); void main() int arrMM=1, 4, 3, 2, 4, 4, 6, 2, 5, 0, 3, 5, 2, 0, 1, 7, 0, 5, 7, 3, 5, 3.1, 9, 2; system(“CLS“); printf(

5、/nThe sum of all elements on 2 diagnals is%d“, proc(M, arr); (分数:40.00)_三、程序设计题(总题数:1,分数:30.00)3.请编写一个函数 void proc(int m, int k, int xx),该函数的功能是将大于整数 m 且紧靠 m 的 k 个非素数存入所指的数组中。 例如,若输入:10 5(即 M=10,k=5),则应输出:12 14 15 16 18。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #incl

6、udestdlib.h #includeconio.h #includestdio.h void proc(int m, int k, int xx) void main() int m, n, zz1000; system(“CLS“); printf(“nPlease enter two integers: “); scanf(”dd”, proc(m, n, zz); for(m=0; mn; m+) printf(“d“, zzm); printf(“n“); (分数:30.00)_二级 C 语言-307 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数

7、1,分数:30.00)1.下列给定程序中,请补充函数 proc(),该函数的功能是:输出数组元素中小于平均值的元素。在主函数 main()中,从键盘输入若干个数放入数组 str 中,并以 0 结束输入但不计入数组。 例如,数组中元素的值依次为 2 3 4 5 5,则程序的运行结果为 2,3。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includeconio.h #includestclio.h void proc( 1, int n) doubl

8、e sum=0.0; double average=0.0; int i=0; for(i=0; in; i+) 2; average= 3; for(i=0; in; i+) if(xiaverage) if(i%5=0) printf(“/n“); printf(“%d, “, xi); void main() int str1000; int i=0; system(“CLS“); printf(“/nPlease enter some data(endwith 0):“); do scanf(“%d“, while(stri+!=0); proc(str, i-1); (分数:30.0

9、0)解析:int x sum+=xi sum/n解析 根据 main()函数中宾参的类型可知第一处填“intx”;要算出所有元素的平均值,可以先算出所有元素的总和,然后再算出平均值,因此,第二处填“sum+=xi”;第三处填“sum/n”。二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中,函数 proc()的功能是:输出 M 行 M 列整数方阵,然后求两条对角线上的各元素之和并将其返回。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行。也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.

10、h #includestdio.h #define M 5 /*found* int proc(int n, int xx) int i, j, sum=0; printf(“/nThe%d x%d matrix:/n“, M, M); for(i=0; iM; i+) for(j=0; jM; j+) /*found* printf(“%4f“, xxij); printf(“/n“); for(i=0; in; i+) sum+=xxii+xxin-i-1; return(sum); void main() int arrMM=1, 4, 3, 2, 4, 4, 6, 2, 5, 0, 3

11、 5, 2, 0, 1, 7, 0, 5, 7, 3, 5, 3.1, 9, 2; system(“CLS“); printf(“/nThe sum of all elements on 2 diagnals is%d“, proc(M, arr); (分数:40.00)_正确答案:()解析:(1)错误:int proc(int n, int xx) 正确:int proc(int n, int xxM) (2)错误:printf(“%4f“, xxij); 正确:printf(“%4d“, xxij); 解析 从主函数中的调用语句可知,实参中的一个为二维数组,因此其形参类型也应该一样,而二

12、维时,其列下标必须是常量,因此把“int proc(int n, int xx)”改为“intproc(int n, int xxM)”。从形参中可知 xx 数组是整型数组,因此其输出的控制应为整型,故把 printf 中的“%4f“改为“%4d“。三、程序设计题(总题数:1,分数:30.00)3.请编写一个函数 void proc(int m, int k, int xx),该函数的功能是将大于整数 m 且紧靠 m 的 k 个非素数存入所指的数组中。 例如,若输入:10 5(即 M=10,k=5),则应输出:12 14 15 16 18。 注意:部分源程序给出如下。 请勿改动 main()函

13、数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdlib.h #includeconio.h #includestdio.h void proc(int m, int k, int xx) void main() int m, n, zz1000; system(“CLS“); printf(“nPlease enter two integers: “); scanf(”dd”, proc(m, n, zz); for(m=0; mn; m+) printf(“d“, zzm); printf(“n“); (分数:30.00)_正确答案:()解析:void proc(int m, int k, int xx) int i, j, n; for(i=m+1, n=0; nk; i+)/用大于 m 的数来判断是否符合条件 for(j=2; ji; j+) if(i%j=0) /判断 i 是否为素数,如果不是则把其放到 xx 数组中 xxn+=i; break; 解析 通过要求把非素数的数放到 xx 数组中,检查大于整数 m 的整数,将不是素数的整数放在数组xx 中,直到个数大于 k 个结束。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 2071-2003 Aerospace series - Sheets in aluminium and aluminium alloys thickness 0 25 mma6 mm - Dimensions German and English version EN 2071 2001《航空航天系列 厚度0 25mm a 6mm的铝及铝合金.pdf DIN EN 2071-2003 Aerospace series - Sheets in aluminium and aluminium alloys thickness 0 25 mma6 mm - Dimensions German and English version EN 2071 2001《航空航天系列 厚度0 25mm a 6mm的铝及铝合金.pdf
  • DIN EN 2072-2007 Aerospace series - Aluminium AL-P1050A-H14 - Sheet and strip - 0 4 mm a 6 mm German and English version EN 2072 2005《航空航天系列 AL-P1050A-H14铝合金 薄板与带材 0 4≥a≥6mm》.pdf DIN EN 2072-2007 Aerospace series - Aluminium AL-P1050A-H14 - Sheet and strip - 0 4 mm a 6 mm German and English version EN 2072 2005《航空航天系列 AL-P1050A-H14铝合金 薄板与带材 0 4≥a≥6mm》.pdf
  • DIN EN 2076-1 A1-1993 Aerospace series aluminium and magnesium alloy ingots and castings technical specification part 1 general requirements German version EN 2076-1 A1 1993 amendm.pdf DIN EN 2076-1 A1-1993 Aerospace series aluminium and magnesium alloy ingots and castings technical specification part 1 general requirements German version EN 2076-1 A1 1993 amendm.pdf
  • DIN EN 2076-1-1990 Aerospace series aluminium and magnesium alloy ingots and castings technical specification part 1 general requirements german version EN 2076-1 1989《航空航天 铝 镁合金铸件.pdf DIN EN 2076-1-1990 Aerospace series aluminium and magnesium alloy ingots and castings technical specification part 1 general requirements german version EN 2076-1 1989《航空航天 铝 镁合金铸件.pdf
  • DIN EN 2076-2-1990 Aerospace series aluminium and magnesium alloy ingots and castings technical specification part 2 ingots for remelting german version EN 2076-2 1989《航空航天 铝 镁合金铸件.pdf DIN EN 2076-2-1990 Aerospace series aluminium and magnesium alloy ingots and castings technical specification part 2 ingots for remelting german version EN 2076-2 1989《航空航天 铝 镁合金铸件.pdf
  • DIN EN 2076-3-1990 Aerospace series aluminium and magnesium alloy ingots and castings technical specification part 3 pre-production and production castings german version EN 2076-3.pdf DIN EN 2076-3-1990 Aerospace series aluminium and magnesium alloy ingots and castings technical specification part 3 pre-production and production castings german version EN 2076-3.pdf
  • DIN EN 2078-2003 Aerospace series - Metallic materials - Manufacturing schedule inspection schedule inspection and test report Definition general principles preparation and approva.pdf DIN EN 2078-2003 Aerospace series - Metallic materials - Manufacturing schedule inspection schedule inspection and test report Definition general principles preparation and approva.pdf
  • DIN EN 2079-1995 Aerospace series - Bearings precision ball with flange in corrosion resisting steel for instruments and equipment - Dimensions and loads German version EN 2079 199.pdf DIN EN 2079-1995 Aerospace series - Bearings precision ball with flange in corrosion resisting steel for instruments and equipment - Dimensions and loads German version EN 2079 199.pdf
  • DIN EN 208-2010 Personal eye-protection - Eye-protectors for adjustment work on lasers and laser systems (laser adjustment eye-protectors) German version EN 208 2009《个人护目镜 激光器和激光系统.pdf DIN EN 208-2010 Personal eye-protection - Eye-protectors for adjustment work on lasers and laser systems (laser adjustment eye-protectors) German version EN 208 2009《个人护目镜 激光器和激光系统.pdf
  • 相关搜索

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

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