67. PHP Program to find all the Prime numbers from 1 to 99.
How does this program work?
- This program is used to find all the Prime numbers from 1 to 99 using PHP.
- Prime number means which is only divisible by 1 and that number itself, and cannot divisible by any other number.
- First store the number into variable, then we will find the remainder using loop.
- The counter will be increment if remainder zero, Once number can be divisible by some other number instead of 1 and that number itself, If its value less than three means its a primer number.
Here is the code
<html>
<head>
<title>PHP Program To find all the Prime numbers from 1 to 99</title>
</head>
<body>
<?php
echo (" Prime Numbers from 1 to 99 are: \n");
for($number = 1; $number <=99; $number++)
{
$count = 0;
//Conditon to check find prime numbers
for ( $i = 2; $i <= $number/2; $i++ )
{
if($number%$i == 0 )
{
$count++;
break;
}
}
if( $count == 0 && $number != 1 )
{
echo $number. " ";
}
}
return 0;
?>
</body>
</html>