文件名称:2
介绍说明--下载内容来自于网络,使用问题请自行百度
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
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
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
1999-2046 搜珍网 All Rights Reserved.
本站作为网络服务提供者,仅为网络服务对象提供信息存储空间,仅对用户上载内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。