Dear developers,
I was solving problems to improve my algorithmic abilities. So, here is one of them:
I need to "echo" all the prime numbers to the browser up to certain number.
So, if the number is 8, for example, I need to echo 2,3,5 and 7.
here is my code:
$a = 100;
for($i = 2; $i<=$a; $i++)
{
if($i == 2)
{
echo "2</br>";
}
for($j =3; $j <= ceil($i/2); $j = $j + 2)
{
if($i % 2 == 0)
{
break;
}
if ($i % $j == 0)
{
break;
}
else
{
continue;
}
}
}
not working properly!
Please Help !!!