Tuesday, 1 October 2013

Find Prime No. Using Java Script By:Tanuj Kumar

Find Prime No. Using Java Scrip

Find Prime No. Using Java Script

var num =prompt("Enter a number");
parseInt(num);var i;var b=0; if(num==1)
{
alert("A prime number is a number which has only two factors, 1, and itself. But in the case of 1, there is only one factor: 1. So, 1 is not a prime number");
}
else{
for(i=1;i<=num;i++)
{
var result = num%i;
if(result==0)
{
b++;
} }
if(b<=2)
{
alert("Prime no.");
}
else
{
alert("Not Prime");
}
}

Posted By:Tanuj Kumar 
On:Shareyourconscience

0 comments:

Post a Comment