Math to Compute Next Prime Number

[Total: 1    Average: 1/5]

This will compute prime numbers.

Head Code:

 * This computes the next prime number in sequence
function isPrime(_n)
 var _isPrime=true;
 var _sqrt=Math.sqrt(_n);
 for(var _i=2;_i<=_sqrt;_i++)
  if((_n%_i)==0) _isPrime=false;
 return _isPrime;
function nextPrime(_s,_n)
  return --_s;
function reduce()
 var _f=document.form1;
 var _s=parseInt(_f.start.value);
 var _n=parseInt(_f.nums.value);

Body Code:

<form name=form1>
Start<input type=text name=start value=14><BR>
Number<input type=text name=nums value=2><BR>
Result<input type=text name=result><BR>
<input value="Compute Now" type=button onclick="reduce()">

Times Viewed: 153

Leave a Reply

Your email address will not be published. Required fields are marked *