Source Code:
(back to article)
<?php // PHP code for checking if a number is prime or Not // function for checking if the number is Prime or Not function primeCheck($number) { if ($number == 1 || $number % 2 == 0) { return false; } for ($i = 3; $i <= sqrt($number); $i += 2) { if ($number % $i == 0) { return false; } } return true; } // Driver Code $number = 31; if (primeCheck($number)) { echo "Prime"; } else { echo "Not Prime"; }
Result:
Report an issue