【计算机类职业资格】三级数据库技术机试-102及答案解析.doc

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

1、三级数据库技术机试-102 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.下列程序的功能是:将不超过整数 m(m2000)的所有素数存入数组 xx。请编写函数 num(int m,int xx)实现程序的要求,最后调用函数 readwriteDat()把结果输出到文件 out.dat 中。例如:若输入 30,则应输出:2,3,5,7,11,13,17,19,23,29。部分源程序已给出。请勿改动主函数 main()和输出数据函数 readwriteDat()的内容。#include conio.h#include stdio.hvoid

2、readwriteDat(); int num(int m, int xx)main ( )int m,n,xx2000;clrscr();printf(“/nPlease enter the integer m:“);scanf(“ %d“ ,n = num(m, xx);for(m-0;mn;m+)printf(“ %d“ ,xxm);printf(“/n“ );readwriteDat();viod readwriteDat ()int m,n,xx1000, i;FILE *rf,*wf;rf=fopen(“in.dat“ ,“ r“ );wf=fopen(“ out.dat“ ,“

3、w“ );for(i=0;i10;i+)fscanf(rf,“ %d“ ,n=num(m, xx);for(m=0;mn;m+)fprintf(wf,“ %d“ ,xxm);fprintf(wf,“/n“ );fclose(rf);fclose(wf);(分数:100.00)_三级数据库技术机试-102 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.下列程序的功能是:将不超过整数 m(m2000)的所有素数存入数组 xx。请编写函数 num(int m,int xx)实现程序的要求,最后调用函数 readwriteDat()把结果输出到文件

4、 out.dat 中。例如:若输入 30,则应输出:2,3,5,7,11,13,17,19,23,29。部分源程序已给出。请勿改动主函数 main()和输出数据函数 readwriteDat()的内容。#include conio.h#include stdio.hvoid readwriteDat(); int num(int m, int xx)main ( )int m,n,xx2000;clrscr();printf(“/nPlease enter the integer m:“);scanf(“ %d“ ,n = num(m, xx);for(m-0;mn;m+)printf(“ %

5、d“ ,xxm);printf(“/n“ );readwriteDat();viod readwriteDat ()int m,n,xx1000, i;FILE *rf,*wf;rf=fopen(“in.dat“ ,“ r“ );wf=fopen(“ out.dat“ ,“ w“ );for(i=0;i10;i+)fscanf(rf,“ %d“ ,n=num(m, xx);for(m=0;mn;m+)fprintf(wf,“ %d“ ,xxm);fprintf(wf,“/n“ );fclose(rf);fclose(wf);(分数:100.00)_正确答案:(提示:类型:素数筛选。关键点:素数

6、筛选算法。求给定范围 1n 内的所有素数的题,可以使用筛选法,步骤如下:创建一个 0-1 标志数组,对应 1n,1 代表该数非素数,0 代表素数。初始化全为 0,以下面的方式将某些位置以 1 标记:(1) 标记位置 1 为 1(1 不是素数),当前位置为 2。(2) 从当前位置开始,找到第一个标记为 0 的数 p,p 是素数;若找不到,转到 6。(3) 遍历数组,将所有 p 的倍数的位置标记为 1。(4) 当前位置前进到 p+1。(5) 返回 2 继续。(6) 输出数组中所有标记为 0 的数(此步可并入第 2 步,找到一个输出一个)。解答:int hum(int m, int xx)int s=0;int flag2000;/*初始化标记数组*/for (i=0; i=m; i+)flagi=0;/*0 和 1 不是素数*/flag0=flag1=1;/*从 2 开始搜索素数*/for(i=2; i=m;i+)/*被标记为 1 的不是素数*/if(flagi)continue;/*i 是素数,输出*/xxs+=i;/*将所有 i 的倍数标记为 1*/*小优化:小于 i*i 的数必有小于 i 的素因数,已标记*/for(j=i*i;i=m;j+=i)flagj=1;/*返回不超过 m 的素数个数*/return S;)解析:

展开阅读全文
相关资源
猜你喜欢
  • NF P43-008-1985 Valves and taps for water supply in buildings Non controllable check valves class B General technical specifications 《建筑物水管阀门 B级非控制非止回动阀 一般技术规范》.pdf NF P43-008-1985 Valves and taps for water supply in buildings Non controllable check valves class B General technical specifications 《建筑物水管阀门 B级非控制非止回动阀 一般技术规范》.pdf
  • NF P43-011-1985 Valves and taps for water supply in buildings Cb disconnectors with different non controllable pressure ranges General technical specifications 《建筑物水管阀门 非受控不同压力范围Cb.pdf NF P43-011-1985 Valves and taps for water supply in buildings Cb disconnectors with different non controllable pressure ranges General technical specifications 《建筑物水管阀门 非受控不同压力范围Cb.pdf
  • NF P43-015-1985 Valves and taps water supply in buildings Draw off taps General technical specifications 《建筑物水管阀门 节流阀 通用技术规范》.pdf NF P43-015-1985 Valves and taps water supply in buildings Draw off taps General technical specifications 《建筑物水管阀门 节流阀 通用技术规范》.pdf
  • NF P43-017-1989 Valves and taps for water supply in buldings Controllable check valves ea with flanges General technical specifications 《建筑物水管阀门 带法兰可调EA止回阀 通用技术规范》.pdf NF P43-017-1989 Valves and taps for water supply in buldings Controllable check valves ea with flanges General technical specifications 《建筑物水管阀门 带法兰可调EA止回阀 通用技术规范》.pdf
  • NF P43-018-1990 Valves and taps for water supply in buildings Checking fitting in place of sanitary protection unities used for drinking supply Specifications 《建筑物水管阀门 饮用水卫生监测仪器 特性.pdf NF P43-018-1990 Valves and taps for water supply in buildings Checking fitting in place of sanitary protection unities used for drinking supply Specifications 《建筑物水管阀门 饮用水卫生监测仪器 特性.pdf
  • NF P43-024-1988 Valves and taps for buildings Hygienic air gap ae General specifications 《建筑物阀门和龙头 AE卫生设施及设备 一般规范》.pdf NF P43-024-1988 Valves and taps for buildings Hygienic air gap ae General specifications 《建筑物阀门和龙头 AE卫生设施及设备 一般规范》.pdf
  • NF P45-204-1-2001 Gas installation in domestic premises - Part 1  terminology 《家用燃气设施 第1部分 术语》.pdf NF P45-204-1-2001 Gas installation in domestic premises - Part 1 terminology 《家用燃气设施 第1部分 术语》.pdf
  • NF P45-204-2-2001 Gas installation in domestic premises - Partie 2  technical specifications - General dispositions 《家用燃气设施 第2部分 技术规范 总部署》.pdf NF P45-204-2-2001 Gas installation in domestic premises - Partie 2 technical specifications - General dispositions 《家用燃气设施 第2部分 技术规范 总部署》.pdf
  • NF P45-204-3-2006 Building work - Gas installation in domestic permises - Part 3  technical specifications - Particular dispositions except the combustion products evacuation 《建筑业 .pdf NF P45-204-3-2006 Building work - Gas installation in domestic permises - Part 3 technical specifications - Particular dispositions except the combustion products evacuation 《建筑业 .pdf
  • 相关搜索

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

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