Find the prime numbers in a range using JavaScript

Submitted by UMBRO
on May 9, 2006 - 5:32pm

A number is a prime number if it's an integer greater than zero and it can not be divided exactly by other integers except 1 and itself.

So number 1, 2 and 3 are prime numbers.

Beyond number 3, If a number is not a prime number, it can be divided exactly by one of the integers between 2 and the square root of this number.This is the most efficient way to identify a prime number.

There's an example code in the HTML file attatched.

AttachmentSize
PrintPrimeNumber.html1.71 KB

1 is not a prime number

pepsiman
on
May 10, 2006 - 7:49am

From http://en.wikipedia.org/wiki/Prime_number

"a prime number (or a prime) is a natural number that has exactly two (distinct) natural number divisors, which are 1 and the prime number itself."

and

"The first 30 prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, and 113"

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.