Home > Backend Development > PHP Tutorial > Example of php outputting prime numbers (prime numbers) within 1000_PHP tutorial

Example of php outputting prime numbers (prime numbers) within 1000_PHP tutorial

WBOY
Release: 2016-07-13 10:24:59
Original
1415 people have browsed it

Copy code The code is as follows:

for($i = 2; $i < 1001; $i++) {
$primes = 0;
for($k = 1; $k <= $i; $k++)
if($i%$k === 0) $primes++;
if($primes <= 2) // An integer that can be divided by 1 and itself (excluding 0)
echo "{$i}< br />";
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825246.htmlTechArticleCopy the code as follows: ?php for($i = 2; $i 1001; $i++) { $primes = 0; for($k = 1; $k = $i; $k++) if($i%$k === 0) $primes++; if($primes = 2)// Can be divided by 1 and itself Integer (excluding...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template