| home | contents | send comment | send link | add bookmark |

Prime number generator

by Stephen R. Schmitt

count


Contents

  1. About
  2. The source code
  3. Discussion

1. About

This Java Script calculator generates a list of prime numbers and factored composite numbers. To operate the calculator, enter the largest integer desired for the list. Press the Compute button to generate the list in a separate window. On invalid entries, a popup window will display an error message.

Return to Contents


2. The source code

The Java Script source code for this program can be viewed by using the View|Source command of your web browser.

You may use or modify this source code in any way you find useful, provided that you agree that the author has no warranty, obligations or liability. You must determine the suitability of this source code for your use.

Return to Contents


3. Discussion

An integer greater than one is a prime number if its only divisors are itself and one. Non-prime numbers are called composite. The number 18 is composite; it is composed of 2×3×3. Conversely, the number 19 is a prime number.

One way to generate prime numbers is to test each number to see if it can be factored by all of the odd numbers up to the square root of the number being tested. It is not necessary to test above the square root of the number since all other combinations of factors would include one number larger than the square root, and one smaller. That is, it would be superfluous to check numbers larger than the square root.

Reference/u>

Elementary Mathematical Analysis

Return to Contents


AbCd Classics - free on-line books


Copyright © 2004, Stephen R. Schmitt