【计算机类职业资格】二级C语言机试-302及答案解析.doc

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

1、二级 C语言机试-302 及答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)1.请补充 main函数,该函数的功能是:从键盘输入 3个整数,然后找出最大的数并输出。例如,输入:12,45,43,最大值为 45。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。试题程序:#includestdio.h#includeconio.hmain()int a, b, c, max;clrscr();printf(“/nlnput three numbers:/n“);scan

2、f(“%d,%d,%d“,printf(“The three numbers are:%d,%d,%d/n“,a,b,c);if(ab)【1】 ;else【2】 ;if(maxc)【3】 ;printf(“max=%d/n“,max);(分数:30.00)填空项 1:_二、改错题(总题数:1,分数:30.00)2.下列给定的程序中,函数 fun()的功能是:计算并输出 k以内最大的 10个能被 13或 17整除的自然数之和。K 的值由主函数传入,若 k的值为 500,则函数的值为 4622。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的

3、结构。试题程序:#includestdio.h#include conio.hint fun(int k)int m=0,mc=0, j;while(k=2)mc+;k-;/*found*/return m;main()clrscr();printf(“%d/n “,fun(500);(分数:30.00)_三、编程题(总题数:1,分数:40.00)3.请编写函数 fun(),函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。例如:若二维数组中的值为1 3 5 7 92 9 9 9 46 9 9 9 81 3 5 7 0则函数值为 61。注意:部分源程序给出如下

4、请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入所编写的若干语句。试题程序:#includeconio.h#includestdio.h#define M 4#define N 5int fun( int a MN)main()int aaMN=1,3,5,7,9,2,9,9,9,4,6,9,9,9,8,1,3,5,7,0;int i, j, y;clrscr();printf (“The original data is :/n “);for(i=0; iN;i+)for (j=0; jN;j+)printf(“%6d “,aaij);printf(“/n “

5、);y=fun(aa);printf(“/nThe sun:%d/n “,y);printf(“/n“);(分数:40.00)_二级 C语言机试-302 答案解析(总分:100.00,做题时间:90 分钟)一、填空题(总题数:1,分数:30.00)1.请补充 main函数,该函数的功能是:从键盘输入 3个整数,然后找出最大的数并输出。例如,输入:12,45,43,最大值为 45。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。试题程序:#includestdio.h#includeconio.hmain()in

6、t a, b, c, max;clrscr();printf(“/nlnput three numbers:/n“);scanf(“%d,%d,%d“,printf(“The three numbers are:%d,%d,%d/n“,a,b,c);if(ab)【1】 ;else【2】 ;if(maxc)【3】 ;printf(“max=%d/n“,max);(分数:30.00)填空项 1:_ (正确答案:1 max=a 2 max=b 3 max=c)解析:解析 填空 1:如果 a大于 b,则 a为 a,b 中的最大值,将 a赋给 inax。填空 2:如果 a小于b,则 b为 a,b 中的最

7、大值,将 b赋给 max。填空 3:最后将 a,b 中的最大值与 c进行比较,如果 c更大,则 c为 3个数中的最大数,将 c赋给 max,否则最大数 max不变。二、改错题(总题数:1,分数:30.00)2.下列给定的程序中,函数 fun()的功能是:计算并输出 k以内最大的 10个能被 13或 17整除的自然数之和。K 的值由主函数传入,若 k的值为 500,则函数的值为 4622。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。试题程序:#includestdio.h#include conio.hint fun(int k)

8、int m=0,mc=0, j;while(k=2)mc+;k-;/*found*/return m;main()clrscr();printf(“%d/n “,fun(500);(分数:30.00)_正确答案:(1)错误:if(k%13=0)|(k%17=0) 正确:if(k%13=0)|(k%17=0)(2) 错误:缺少大括号 正确:加)解析:解析 能被某个数整除的表示方法是 x%y=0,而并非像题目中所表示的 if(k%13=0)|(k%17=0),所以, if(k%13=0)|(k%17=0)修改后的结果应该是答案所示信息,(2)中缺少程序完整所需的“”,此类信息在做题时一定注意,我们

9、可以在上机考试的时候先运行一下程序,这样明显的错误一般都会有错误信息显示出来,比如丢失“”的错误信息是“Compound statement missing in function fun”,并在当前错误处停止光标,我们只要按回车键进行编辑就可以了。三、编程题(总题数:1,分数:40.00)3.请编写函数 fun(),函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。例如:若二维数组中的值为1 3 5 7 92 9 9 9 46 9 9 9 81 3 5 7 0则函数值为 61。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在函数

10、 fun的花括号中填入所编写的若干语句。试题程序:#includeconio.h#includestdio.h#define M 4#define N 5int fun( int a MN)main()int aaMN=1,3,5,7,9,2,9,9,9,4,6,9,9,9,8,1,3,5,7,0;int i, j, y;clrscr();printf (“The original data is :/n “);for(i=0; iN;i+)for (j=0; jN;j+)printf(“%6d “,aaij);printf(“/n “);y=fun(aa);printf(“/nThe sun:%d/n “,y);printf(“/n“);(分数:40.00)_正确答案:(int fun( int a M N)int i,j,sum=0;for(i=0;iM;i+)for(j=0;iN;j+)if(i=0|i=M-1|j=0|j=N-1) /*只要下标中有一个为 0或 M-1或 N-1,则它一定是周边元素*/sum=sum+aij; /*将周边元素相加*/return sum;)解析:解析 本题采用逐一判断的方式,周边元素的下标一定有一个是 0或 M-1或 N-1,且只要下标中有一个为 0或 M-1或 N-1,则它一定是周边元素。

展开阅读全文
相关资源
猜你喜欢
  • IEC 61987-15-2016 Industrial-process measurement and control - Data structures and elements in process equipment catalogues - Part 15 Lists of properties (LOPs) for level measuring.pdf IEC 61987-15-2016 Industrial-process measurement and control - Data structures and elements in process equipment catalogues - Part 15 Lists of properties (LOPs) for level measuring.pdf
  • IEC 61987-16-2016 Industrial-process measurement and control - Data structures and elements in process equipment catalogues - Part 16 Lists of properties (LOPs) for density measuri.pdf IEC 61987-16-2016 Industrial-process measurement and control - Data structures and elements in process equipment catalogues - Part 16 Lists of properties (LOPs) for density measuri.pdf
  • IEC 61987-21-2015 Industrial-process measurement and control - Data structures and elements in process equipment catalogues - Part 21 List of Properties (LOP) of automated valves f.pdf IEC 61987-21-2015 Industrial-process measurement and control - Data structures and elements in process equipment catalogues - Part 21 List of Properties (LOP) of automated valves f.pdf
  • IEC 61987-24-2-2017 Industrial-process measurement and control - Data structures and elements in process equipment catalogues - Part 24-2 Lists of properties (LOPs) of valve actuat.pdf IEC 61987-24-2-2017 Industrial-process measurement and control - Data structures and elements in process equipment catalogues - Part 24-2 Lists of properties (LOPs) of valve actuat.pdf
  • IEC 61987-24-3-2017 Industrial-process measurement and control - Data structures and elements in process equipment catalogues - Part 24-3 Lists of properties (LOPs) of flow modific.pdf IEC 61987-24-3-2017 Industrial-process measurement and control - Data structures and elements in process equipment catalogues - Part 24-3 Lists of properties (LOPs) of flow modific.pdf
  • IEC 61988-1-2011 Plasma display panels - Part 1 Terminology and letter symbols《等离子体显示板.第1部分 术语和字母符号》.pdf IEC 61988-1-2011 Plasma display panels - Part 1 Terminology and letter symbols《等离子体显示板.第1部分 术语和字母符号》.pdf
  • IEC 61988-2-1-2012 Plasma Display Panels - Part 2-1 Measuring methods - Optical and optoelectrical《等离子体显示板.第2-1部分 光学和光电学测量方法》.pdf IEC 61988-2-1-2012 Plasma Display Panels - Part 2-1 Measuring methods - Optical and optoelectrical《等离子体显示板.第2-1部分 光学和光电学测量方法》.pdf
  • IEC 61988-2-4-2011 Plasma display panels - Part 2-4 Measuring methods - Visual quality Image artifacts《等离子显示板.第2-4部分 测量方法.视觉质量 图像伪影》.pdf IEC 61988-2-4-2011 Plasma display panels - Part 2-4 Measuring methods - Visual quality Image artifacts《等离子显示板.第2-4部分 测量方法.视觉质量 图像伪影》.pdf
  • IEC 61988-2-5-2012 Plasma display panels - Part 2-5 Measuring methods - Acoustic noise《等离子显示器.第2-5部分 测量方法.噪声》.pdf IEC 61988-2-5-2012 Plasma display panels - Part 2-5 Measuring methods - Acoustic noise《等离子显示器.第2-5部分 测量方法.噪声》.pdf
  • 相关搜索

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

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