CDN加速镜像 | 设为首页 | 加入收藏夹
当前位置: 首页 资源下载 源码下载 Windows编程 数据库编程

文件名称:2

  • 所属分类:
  • 标签属性:
  • 上传时间:
    2014-12-27
  • 文件大小:
    115.33kb
  • 已下载:
    1次
  • 提 供 者:
  • 相关连接:
  • 下载说明:
    别用迅雷下载,失败请重下,重下不扣分!

介绍说明--下载内容来自于网络,使用问题请自行百度

1.  编写筛选查找素数函数:

void sieve(bool isPrime[], int n)

其中isPrime[n]为一个布尔型数组,n为数组大小。由于2是第一个素数,所以设置isPrime[0]和isPrime[1]的值为false,并设置其余的元素初值为true。然后对从4到n-1的每一个i,判断i是否能够被2整除,如果i能够被2整除,则设置isPrime[i]为false。对从2到n/2的每一个可能的数值重复以上处理,当操作结束时,所有值为true的isPrime[i]所对应的i就是素数,它们将是从筛子中掉下来的。

测试程序:

输入:一个整数,表示n

输出:1行,1到n之间的所有素数,两个素数之间用空格隔开,最后一个素数输出后,输出一个空格和空行,输出参见函数Disp的代码。

例如,当输入20时,输出如下:

2 3 5 7 11 13 17 19

-1. Preparation of screening to find primes function: void sieve (bool isPrime [], int n) where isPrime [n] is a Boolean array, n is the array size. Because 2 is the first prime number, so set isPrime [0] and isPrime [1] the value is false, and set the rest of the elements of the initial value to true. Then 4 to n-1 every i, i determine whether it can be divisible by 2, if i can be divisible by 2, set isPrime [i] is false. For every possible value 2 to n/2 Repeat the above process, when the end of the operation, all the value of true isPrime [i] corresponding to the i is a prime number, they will be falling the sieve come. Test Procedure: Input: An integer representing the n output: 1 line, all the prime numbers between 1 and n, separated by a space between two prime number, a prime number after the last output, the output of a blank and blank lines, see the output function Disp code. For example, when the input 20, the output is as follows: 235711131719
(系统自动生成,下载前可以参看下载内容)

下载文件列表

2/3.cpp
2/c++_ch06_03.vcxproj
2/c++_ch06_03.vcxproj.filters
2/Debug/3.obj
2/Debug/c++_ch06_03.lastbuildstate
2/Debug/c++_ch06_03.log
2/Debug/cl.command.1.tlog
2/Debug/CL.read.1.tlog
2/Debug/CL.write.1.tlog
2/Debug/link-cvtres.read.1.tlog
2/Debug/link-cvtres.write.1.tlog
2/Debug/link-rc.read.1.tlog
2/Debug/link-rc.write.1.tlog
2/Debug/link.2484-cvtres.read.1.tlog
2/Debug/link.2484-cvtres.write.1.tlog
2/Debug/link.2484-rc.read.1.tlog
2/Debug/link.2484-rc.write.1.tlog
2/Debug/link.2484.read.1.tlog
2/Debug/link.2484.write.1.tlog
2/Debug/link.4604-cvtres.read.1.tlog
2/Debug/link.4604-cvtres.write.1.tlog
2/Debug/link.4604-rc.read.1.tlog
2/Debug/link.4604-rc.write.1.tlog
2/Debug/link.4604.read.1.tlog
2/Debug/link.4604.write.1.tlog
2/Debug/link.command.1.tlog
2/Debug/link.read.1.tlog
2/Debug/link.write.1.tlog
2/Debug/vc110.idb
2/Debug/vc110.pdb
2/Debug
2

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 搜珍网是交换下载平台,只提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。更多...
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或换浏览器;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.

相关评论

暂无评论内容.

发表评论

*快速评论: 推荐 一般 有密码 和说明不符 不是源码或资料 文件不全 不能解压 纯粹是垃圾
*内  容:
*验 证 码:
搜珍网 www.dssz.com