【计算机类职业资格】三级信息管理技术机试-292及答案解析.doc

上传人:priceawful190 文档编号:1320763 上传时间:2019-10-17 格式:DOC 页数:4 大小:28.50KB
下载 相关 举报
【计算机类职业资格】三级信息管理技术机试-292及答案解析.doc_第1页
第1页 / 共4页
【计算机类职业资格】三级信息管理技术机试-292及答案解析.doc_第2页
第2页 / 共4页
【计算机类职业资格】三级信息管理技术机试-292及答案解析.doc_第3页
第3页 / 共4页
【计算机类职业资格】三级信息管理技术机试-292及答案解析.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、三级信息管理技术机试-292 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知数据文件 IN39.DAT 中存有 300 个 4 位数,并已调用读函数 readDat()把这些数存入数组 a 中,请编制一函数 jsValue(),其功能是:求出这些 4 位数是素数的个数 ent,再把所有满足此条件的 4 位数依次存人数组 b 中,然后对数组 b 中的 4 位数按从小到大的顺序进行排序,最后调用函数 writeDat()把数组 b 中的数输出到 OUT39DAT 文件中。例如:5591 是素数,则该数满足条件,存人数组 b 中,且个数 c

2、nt=cnt+1。9812 是非素数,则该数不满足条件,忽略。注意:部分源程序已给出。程序中已定义数组:a300,b300,已定义变量:cnt。请勿改动主函数 main()、读函数 readDat()和写函数 wfiteDat()的内容。试题程序#includestdio.hint a300,b300,cnt=0;void readDat();void writeDat();int isP(int m)int i;for(i=2;im;i+)if(m%i=0)return 0;return i;void jsValue()void main()int i;readDat();jsValue()

3、writeDat();printf(“cnt=%d/n“,cnt);for(i=0;icnt;i+)printf(“b%d=%d/n“,i,bi);void readDat()FILE*fp;int i;fp=fopen(“IN39.DAT“,“r“);for(i=0;i300;i+)fscanf(fp,“%d,“,fclose(fp);void writeDat()FILE*fp;int i;fp=fopen(“OUT39.DAT“,“w“);fprintf(fp,“%d/n“,cnt);for(i=0;icnt;i+)fprintf(fp,“%d/n“,bi);fclose(fp);(分

4、数:100.00)_三级信息管理技术机试-292 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知数据文件 IN39.DAT 中存有 300 个 4 位数,并已调用读函数 readDat()把这些数存入数组 a 中,请编制一函数 jsValue(),其功能是:求出这些 4 位数是素数的个数 ent,再把所有满足此条件的 4 位数依次存人数组 b 中,然后对数组 b 中的 4 位数按从小到大的顺序进行排序,最后调用函数 writeDat()把数组 b 中的数输出到 OUT39DAT 文件中。例如:5591 是素数,则该数满足条件,存人数组

5、b 中,且个数 cnt=cnt+1。9812 是非素数,则该数不满足条件,忽略。注意:部分源程序已给出。程序中已定义数组:a300,b300,已定义变量:cnt。请勿改动主函数 main()、读函数 readDat()和写函数 wfiteDat()的内容。试题程序#includestdio.hint a300,b300,cnt=0;void readDat();void writeDat();int isP(int m)int i;for(i=2;im;i+)if(m%i=0)return 0;return i;void jsValue()void main()int i;readDat();

6、jsValue();writeDat();printf(“cnt=%d/n“,cnt);for(i=0;icnt;i+)printf(“b%d=%d/n“,i,bi);void readDat()FILE*fp;int i;fp=fopen(“IN39.DAT“,“r“);for(i=0;i300;i+)fscanf(fp,“%d,“,fclose(fp);void writeDat()FILE*fp;int i;fp=fopen(“OUT39.DAT“,“w“);fprintf(fp,“%d/n“,cnt);for(i=0;icnt;i+)fprintf(fp,“%d/n“,bi);fclo

7、se(fp);(分数:100.00)_正确答案:(void jsValue()int i,j; /*定义循环控制变量*/int temp: /*定义数据交换时的暂存变量*/for(i=0;i300;i+) /*逐个取 4 位数*/if(isP(ai) /*如果该数为素数,则将该数存入数组 b 中*/bcnt=ai;cnt+; /*并统计满足条件的数的个数*/for(i=0;icnt-1;i+) /*对数组 b 中的 4 位数按从小到大的顺序进行排序*/for(j=i+1;jcnt;j+)if(bibj)temp=bi;bi=bj;bj=temp;)解析:解析 根据题意可知,函数 jsValue()要实现两个功能:一是找出满足条件的那些数,本题中为素数,并存放在数组 b 中;二是对数组 b 中的数进行从小到大的排序。首先要找出满足条件的数,即素数,题目中已给出了判断素数的函数,因此只需调用即可。其次,将这些素数存入数组 b 中,并用变量 cnt 来统计数组 b 中元素的个数。最后,将所有满足条件的数取出后利用选择法进行排序,即将当前元素依次同它后面的元素进行比较,发现有大于该数的数,就将这两数进行交换。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 13830-2015 Curtain walling - Product standard German version EN 13830 2015《幕墙 产品标准 德文版本EN 13830-2015》.pdf DIN EN 13830-2015 Curtain walling - Product standard German version EN 13830 2015《幕墙 产品标准 德文版本EN 13830-2015》.pdf
  • DIN EN 13831-2007 Closed expansion vessels with built in diaphragm for installation in water English version of DIN EN 13831 2007-12《水中装置用安装在隔膜内的封闭式膨胀罐》.pdf DIN EN 13831-2007 Closed expansion vessels with built in diaphragm for installation in water English version of DIN EN 13831 2007-12《水中装置用安装在隔膜内的封闭式膨胀罐》.pdf
  • DIN EN 13832-1-2006 Footwear protecting against chemicals - Part 1 Terminology and test methods English version of DIN EN 13832-1 2006-11《防化学性鞋靴 第1部分 术语和试验方法》.pdf DIN EN 13832-1-2006 Footwear protecting against chemicals - Part 1 Terminology and test methods English version of DIN EN 13832-1 2006-11《防化学性鞋靴 第1部分 术语和试验方法》.pdf
  • DIN EN 13832-2-2006 Footwear protecting against chemicals - Part 2 Requirements for footwear resistant to chemicals under laboratory conditions English version of DIN EN 13832-2 20.pdf DIN EN 13832-2-2006 Footwear protecting against chemicals - Part 2 Requirements for footwear resistant to chemicals under laboratory conditions English version of DIN EN 13832-2 20.pdf
  • DIN EN 13832-3-2006 Footwear protecting against chemicals - Part 3 Requirements for footwear highly resistant to chemicals under laboratory conditions English version of DIN EN 138.pdf DIN EN 13832-3-2006 Footwear protecting against chemicals - Part 3 Requirements for footwear highly resistant to chemicals under laboratory conditions English version of DIN EN 138.pdf
  • DIN EN 13834-2009 Cookware - Ovenware for use in traditional domestic ovens (includes Amendment A1 2009) English version of DIN EN 13834 2009-07《炊具 传统家用烘箱用烘箱器皿(包括修改件A1 2009) DIN EN.pdf DIN EN 13834-2009 Cookware - Ovenware for use in traditional domestic ovens (includes Amendment A1 2009) English version of DIN EN 13834 2009-07《炊具 传统家用烘箱用烘箱器皿(包括修改件A1 2009) DIN EN.pdf
  • DIN EN 13835-2012 Founding - Austenitic cast irons German version EN 13835 2012《铸造 奥氏体铸铁》.pdf DIN EN 13835-2012 Founding - Austenitic cast irons German version EN 13835 2012《铸造 奥氏体铸铁》.pdf
  • DIN EN 13842-2004 Oil fired forced convection air heaters - Stationary and transportable for space heating German version EN 13842 2004《燃油式强制对流空气加热器 固定和可移动的空间加热器》.pdf DIN EN 13842-2004 Oil fired forced convection air heaters - Stationary and transportable for space heating German version EN 13842 2004《燃油式强制对流空气加热器 固定和可移动的空间加热器》.pdf
  • DIN EN 13843-2009 Roller sports equipment - Inline-skates - Safety requirements and test methods English version of DIN EN 13843 2009-08《滚轴运动设备 单排轮滑板 安全性要求和试验方法 英文版本DIN EN 13843-20.pdf DIN EN 13843-2009 Roller sports equipment - Inline-skates - Safety requirements and test methods English version of DIN EN 13843 2009-08《滚轴运动设备 单排轮滑板 安全性要求和试验方法 英文版本DIN EN 13843-20.pdf
  • 相关搜索

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

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