【计算机类职业资格】三级网络技术机试-259及答案解析.doc

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

1、三级网络技术机试-259 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知数据文件 IN27.DAT 中存有 300 个 4 位数,并已调用读函数 readDat()把这些数存入数组 a 中,请编制一函数 jsValue(),其功能是:求出千位数上的数加百位数上的数等于十位数上的数加个位数上的数的个数 cnt,再把所有满足此条件的 4 位数依次存入数组 b 中,然后对数组 b 的 4 位数从大到小进行排序,最后调用写函数 writeDat()把数组 b 中的数输出到 OUT27.DAT 文件。例如:7153,7+1=5+3,则该数满足条

2、件,存入数组 b 中,且个数 cnt=cnt+1。8129,8+12+9,则该数不满足条件,忽略。注意:部分源程序已给出。程序中已定义数组:a300,b300,已定义变量:cnt。请勿改动主函数 main()、读函数 readDat()和写函数 writeDat()的内容。试题程序:#includestdio.hint a300, bi300, cnt=0;void jsValue()main ( )int i;readDat ();jsValue();writeDat ();printf(“cnt=%d/n“, cnt);for(i = 0; i cnt; i+)printf(“b%d=%d

3、/n“, i, bi);readDat ( )FILE *fp;int i;fp = fopen(“IN27.DAT“, “r“);for(i = 0; i 300; i+)fscanf(fp, “%d,“, writeDat ()FILE *fp;int i;fp = fopen(“OUT27.DAT“, “w“);fprintf (fp, “%d/n“,cnt);for(i = 0; i cnt; i+)fprintf(fp, “%d,/n“, bi);fclose (fp);(分数:100.00)_三级网络技术机试-259 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(

4、总题数:1,分数:100.00)1.已知数据文件 IN27.DAT 中存有 300 个 4 位数,并已调用读函数 readDat()把这些数存入数组 a 中,请编制一函数 jsValue(),其功能是:求出千位数上的数加百位数上的数等于十位数上的数加个位数上的数的个数 cnt,再把所有满足此条件的 4 位数依次存入数组 b 中,然后对数组 b 的 4 位数从大到小进行排序,最后调用写函数 writeDat()把数组 b 中的数输出到 OUT27.DAT 文件。例如:7153,7+1=5+3,则该数满足条件,存入数组 b 中,且个数 cnt=cnt+1。8129,8+12+9,则该数不满足条件,

5、忽略。注意:部分源程序已给出。程序中已定义数组:a300,b300,已定义变量:cnt。请勿改动主函数 main()、读函数 readDat()和写函数 writeDat()的内容。试题程序:#includestdio.hint a300, bi300, cnt=0;void jsValue()main ( )int i;readDat ();jsValue();writeDat ();printf(“cnt=%d/n“, cnt);for(i = 0; i cnt; i+)printf(“b%d=%d/n“, i, bi);readDat ( )FILE *fp;int i;fp = fop

6、en(“IN27.DAT“, “r“);for(i = 0; i 300; i+)fscanf(fp, “%d,“, writeDat ()FILE *fp;int i;fp = fopen(“OUT27.DAT“, “w“);fprintf (fp, “%d/n“,cnt);for(i = 0; i cnt; i+)fprintf(fp, “%d,/n“, bi);fclose (fp);(分数:100.00)_正确答案:(void jsValue() int i,thou,hun,ten,data,j;for(i=0;i300;i+)thou=ai/1000; /*求千位数字*/hun=a

7、i%1000/100; /*求百位数字*/ten=ai%100/10; /*求十位数字*/data=ai%10; /*求个位数字*/if(thou+hun=data+ten) /*如果千位数加百位数等于十位数加个位数*/bcnt=ai; /*把满足条件的 4 位数依次存入数组 b 中*/cnt+; /*计算满足条件的数的个数*/for(i=0;icnt-1;i+) /*对数组 b 的 4 位数从大到小进行排序*/for(j=i+1;jcnt;j+)if(bibj)data=bi;bi=bj;bj=data;)解析:解析 根据题意可知,函数 jsValue()用于实现两个功能:一是找出满足条件的

8、数,并存放在数组 b 中:二是对数组 b 中的数进行从大到小的排序。首先来找出“千位数上的数加上百位数上的数等于十位数上的数加上个位数上的数”的 4 位数。利用一个 for 循环来不断从数组 a 中取出 4 位数,并对取出的数进行条件判断。由于这里涉及到要对 4 位数的每一位进行判断,因此,“thou=ai/1000;hun=ai%1000/100;ten=ai%100/10; dam=ai%10;”这 4 条语句就可以得到当前被判断的 4 位数的千位数、百位数、十位数及个位数。之后,执行条件判断语句“if(thou+hun=data+ten)”,并把满足条件的 4 位数存入数组 b 中。变量 cnt 用来统计满足条件的数的个数。将所有满足条件的数取出后利用选择法对其进行排序,即拿当前元素依次和它后面的元素进行比较,发现有大于该数的,就将这两个数进行交换。最终数组 b 的元素就是有序存放的。

展开阅读全文
相关资源
猜你喜欢
  • BS 1747-6-1983 Methods for measurement of air pollution - Sampling equipment used for the determination of gaseous sulphur compounds in ambient air《空气污染的测量方法 第6部分 测定环境空气中气态硫化物的取样设备.pdf BS 1747-6-1983 Methods for measurement of air pollution - Sampling equipment used for the determination of gaseous sulphur compounds in ambient air《空气污染的测量方法 第6部分 测定环境空气中气态硫化物的取样设备.pdf
  • BS 1747-9-1987 Methods for measurement of air pollution Determination of the mass concentration of nitrogen oxides in ambient air chemiluminescence method《空气污染的测量方法 环境空气中氧化氮质量浓度的测定.pdf BS 1747-9-1987 Methods for measurement of air pollution Determination of the mass concentration of nitrogen oxides in ambient air chemiluminescence method《空气污染的测量方法 环境空气中氧化氮质量浓度的测定.pdf
  • BS 1748 Pts 1-5-1961 Methods for the analysis of copper alloys - Methods for the determination of copper lead iron aluminium and nickel in copper alloys《铜合金分析方法 第1部分至第5部分 铜合金中铜、铅、铁.pdf BS 1748 Pts 1-5-1961 Methods for the analysis of copper alloys - Methods for the determination of copper lead iron aluminium and nickel in copper alloys《铜合金分析方法 第1部分至第5部分 铜合金中铜、铅、铁.pdf
  • BS 1748 Pts 11 and 12-1964 Methods for the analysis of copper alloys - Methods for the determination of copper and lead in leaded bronze alloys《铜合金分析方法 含铅青铜合金中铜和铅的测定方法》.pdf BS 1748 Pts 11 and 12-1964 Methods for the analysis of copper alloys - Methods for the determination of copper and lead in leaded bronze alloys《铜合金分析方法 含铅青铜合金中铜和铅的测定方法》.pdf
  • BS 1748-6-1960 Methods for the analysis of copper alloys - Method for the determination of tin in copper alloys (nickel coil reduction method)《铜合金分析方法 第6部分 铜合金中锡的测定方法(镍线圈还原法)》.pdf BS 1748-6-1960 Methods for the analysis of copper alloys - Method for the determination of tin in copper alloys (nickel coil reduction method)《铜合金分析方法 第6部分 铜合金中锡的测定方法(镍线圈还原法)》.pdf
  • BS 1748-7-1960 Methods for the analysis of copper alloys - Method for the determination of silicon in copper alloys (photometric method)《铜合金分析方法 第7部分 铜合金中硅的测定方法(光度测量法)》.pdf BS 1748-7-1960 Methods for the analysis of copper alloys - Method for the determination of silicon in copper alloys (photometric method)《铜合金分析方法 第7部分 铜合金中硅的测定方法(光度测量法)》.pdf
  • BS 1748-8-1960 Methods for the analysis of copper alloys - Method for the determination of phosphorus in copper alloys (photometric method)《铜合金分析方法 第8部分 铜合金中磷的测定方法(光度测量法)》.pdf BS 1748-8-1960 Methods for the analysis of copper alloys - Method for the determination of phosphorus in copper alloys (photometric method)《铜合金分析方法 第8部分 铜合金中磷的测定方法(光度测量法)》.pdf
  • BS 1748-9-1963 Methods for the analysis of copper alloys - Method for the determination of zinc in copper alloys《铜合金分析方法 第9部分 铜合金中锌的测定方法》.pdf BS 1748-9-1963 Methods for the analysis of copper alloys - Method for the determination of zinc in copper alloys《铜合金分析方法 第9部分 铜合金中锌的测定方法》.pdf
  • BS 1751-1997 Laboratory glassware - Specification for straight-bore glass stopcocks for general purposes《实验室玻璃器皿 普通直孔玻璃管塞规范》.pdf BS 1751-1997 Laboratory glassware - Specification for straight-bore glass stopcocks for general purposes《实验室玻璃器皿 普通直孔玻璃管塞规范》.pdf
  • 相关搜索

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

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