Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to calculate and print the first 21,000 prime numbers in JavaScript

1 Answer

0 votes
<script type="text/JavaScript">

var i;
var n = 21000;
var prime = 2;
var numbers = 1;
     
while (numbers <= n)
{
    for (i = 2 ; i <= prime - 1 ; i++)
    {
        if (prime % i == 0)
            break;
    }
    if (i == prime)
    {
        document.write(prime + "<br />");
        numbers++;
    }
    prime++;
}

/*
run:

...

237043
237053
237067
237071
237073
237089
237091
237137
237143
237151
237157
237161
237163
237173
237179
237203

*/
    
</script>

 



answered May 14, 2016 by avibootz
...