Prime Number Program

by admin on September 8th, 2011

function IsPrime($number)
{
if ($number < 2) { /* We don’t want zero or one showing up as prime */
return FALSE;
}
for ($i=2; $i<=($number / 2); $i++) {
if($number % $i == 0) { /* Modulus operator, very useful */
return FALSE;
}
}
return TRUE;
}

for($i = 0; $i < 100; $i++)
{
echo $i.” is a prime number? “.IsPrime($i).”
“;
}

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>