quick links

Find prime number from 1 to 100 and Check given number is prime or not

A prime number is a whole number greater than 1 whose only factors are 1 and itself.

Find from 1 to 100

<?php
for($i=1; $i<=100; $i++) {
$prime = 0;
for($j=1; $j<=$i; $j++) {
if($i%$j == 0) {
$prime++;
}
}
if($prime==2) {
echo $i;echo "  ";
}
}
?>

OUTPUT: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Check given number is prime or not

<?php
$no=11;
for($i=2;$i<=$no/2;$i++)
{
$ans=$no%$i;
if($ans==0)
{
echo $no." Number is not prime";
goto end;
}	
}
echo $no." Number is prime";
end:
?>

OUTPUT: 11 Number is prime

 

About Us

Joomla Web Solution

We love working with PHP, HTML5, CSS3, jQuery and the most-loved content management framework in the world, Joomla!

LIKE US ON FACEBOOK