Pages

Monday, 17 April 2017

Prime Number Program in PHP

Prime Number Program in PHP

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. Here we write Prime Number Program in PHP in very simple and easy way

PHP Code to Print Prime Number

<?php
function IsPrime($n)
{
 for($x=2; $x<$n; $x++)
{
 if($n %$x ==0)
 {
 return 0;
 }
 }
 return 1;
 }
$a = IsPrime(3);
if ($a==0)
{
echo "Not a Prime Number.....'."\n";
}
else
{
echo "Prime Number..'."\n";
}
?>  

I hope this code is helpful for you.

No comments:

Post a Comment