To know the number is prime or not using the programming language PHP, we can use the following method:
$n = 4; // please enter the value of N here
$status = "PRIME";
for ($i = 2; $i <= $n-1; $i++)
if ($n % $i == 0)
$status = "NO PRIME";
echo "Number ".$n." is : ".$status;
$ n = 4; // here you are free to determine what the value or number you want to check, here I am trying to check the status of number 4. if prime prime prime not otherwise status.
4 is not a prime number
is now $n I change into 2
2 is a prime number
If you have any questions please comment.
Do not forget to like and share.
Learn Programming in fajaryusuf.com wrote. 🙂