Eratosthenes sieve in JavaScript


prime<<algorithm


<!DOCTYPE html>
<html>
<body>
<script>
  
var n = prompt("n:", "");
var skr = [], i, j;
if (n < 2) alert("No prime numbers in the given range");
else{
  for(i = 2; i <= n; i++) skr[i] = false;
  i = 2;
  do{
    if (!skr[i]){
      j = i * i;
      while(j <= n){
        skr[j] = true;
        j += i;
      }
    }
    i++;
  } while ((i * i) <= n);
  for(i = 2; i <= n; i++) if (!skr[i]) document.write(i+" ");
}
</script> 
</body>
</html>