topical media & game development

lib-js-math-calculator-primes.htm / htm

```

<!-- THREE STEPS TO INSTALL NUMBER OF PRIMES:

3.  Put the last coding into the BODY of your HTML document  -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original:  Edemar Costa Oliveira (edemar@decisionway.com) -->
<!-- Web Site:  http://edemar.cjb.net -->
<script language=javascript>
/*
Script implements the seive of Erastótenes.
It finds all the prime numbers up to one determined value.
developed by: Edemar C. Oliveira - edemar@hotmail.com
www.edemar.cjb.net
*/
function CriaArray (n) {
this.length = n
for (var i = 1 ; i <= n ; i++)
{ this[i] = 1 }
}

function infP(){

var i, k;
var m;
var npValue =  prompt("type value: ", "" );
var npSize = parseInt(npValue);

if (npSize <= 0) {
return false;
}

var flags = new CriaArray(npSize) ;

for( i=2; i<=flags.length; i++ ){
if( flags[i] )
for( k=i+1; k<=flags.length; k+=i )
flags[k] = 0;
}

if (npSize > 2)
m = 2 + ",";

for( i=0; i<=flags.length; i++  )
if (flags[i] == 0)
m += i + ",";

alert("The numer of primes up to - " + npSize + " are : " + m );
}
</script>

<!-- STEP TWO: Insert the onLoad event handler into your BODY tag  -->

<!-- STEP THREE: Copy this code into the BODY of your HTML document  -->

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin

//  End -->
</script>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size:  2.05 KB -->
```

(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.