Home  >  Article  >  Backend Development  >  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
WBOYOriginal
2016-07-13 10:24:591365browse

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...
Statement:
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