<HTML> | |
<HEAD> | |
<TITLE> Prime Number </TITLE> | |
</HEAD> | |
<script> | |
var inum=prompt("Enter a Value"); | |
var a=new Array(); | |
var val=0; | |
for(var ind = 1;ind<=inum;ind++){ | |
count = 0; | |
for(i=2;i<=ind/2;i++){ | |
if(ind%i==0){ | |
count++; | |
break; | |
} | |
} | |
if(count==0 && ind!= 1){ | |
a[val]=ind; | |
val++; | |
} | |
} | |
var indVal=9; | |
var inc=0; | |
while(inc<a.length) | |
{ | |
inc++; | |
document.write("<font color='#"+ Math.floor(Math.random() * 16777215).toString(16)+"'>"+a[indVal]+"  </font>"); | |
indVal--; | |
if(inc%10==0) | |
{ | |
document.write("<br>"); | |
indVal=inc+9; | |
} | |
if(indVal>a.length) | |
{ | |
var temp=indVal-a.length; | |
indVal=indVal-temp-1; | |
} | |
} | |
</script> | |
<body> | |
</body> | |
</html> | |
Tuesday, July 16, 2013
Prime Numbers in javascript
Labels:
JavaScript
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment