Source Code:
(back to article)
<?php // PHP code for checking if a number is prime or not // function for checking the number is Prime or not function primeCheck($number) { if ($number == 1) { return false; } for ($i = 2; $i <= $number / 2; $i++) { 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