Output prime numbers less than 1000

WBOY
Release: 2016-07-25 08:48:50
Original
1262 people have browsed it
  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


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!