Home  >  Article  >  Backend Development  >  Output prime numbers less than 1000

Output prime numbers less than 1000

WBOY
WBOYOriginal
2016-07-25 08:48:501258browse
  1. for($i = 2; $i < 1001; $i++) {
  2. $primes = 0;
  3. for($k = 1; $k <= $i; $ k++)
  4. if($i%$k === 0) $primes++;
  5. if($primes <= 2) // An integer that can be divided by 1 and itself (excluding 0)
  6. echo " {$i}
    ";
  7. }
Copy code


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