Javscript Program to print PRIME numbers from 1-100.
<html>
<head>
<script type = "text/javascript">
<head>
<script type = "text/javascript">
function finding_primes()
{
var list = "";
for (var number = 2; number<=100; number++)
{
var prime = true;
for ( var i = 2; i < (number/2); i++ )
{
if ( number % i == 0 ) {prime = false}
}
if (prime) { list += "," + number; }
}
document.write ( "primes: " + list.substring(1) );
}
{
var list = "";
for (var number = 2; number<=100; number++)
{
var prime = true;
for ( var i = 2; i < (number/2); i++ )
{
if ( number % i == 0 ) {prime = false}
}
if (prime) { list += "," + number; }
}
document.write ( "primes: " + list.substring(1) );
}
finding_primes();
</script>
</html>
No comments:
Post a Comment