Code:
<!DOCTYPE html>
<html>
<body>
<center>
<h1>Prime Numbers in a Range</h1>
<form name="form1">
Enter Lower limit:
<input type="text" name="lower">
Enter Upper limit:
<input type="text" name="upper">
<input type="button" onclick="myFunction()" value="Try it">
<br>
</form>
<p id="demo"></p>
<script>
function myFunction()
{
var s=" ",j=2,f=1;
var i=document.form1.lower.value;
var n=document.form1.upper.value;
for (i;i<=n;i++)
{
f=1;
for(j=2;j<i;j++)
{
if(i%j==0)
{
f=0;
break;
}
}
if (f==1)
{
s=s+"<br/>"+i;
}
}
document.getElementById("demo").innerHTML=s;
}
</script>
</center>
</body>
</html>
No comments:
Post a Comment