I\'m trying to create a function which checks whether the number is prime or not. BUT I want this function to echo to the user \'prime\' or \'NOT prime\' - and that\'s where my
That is my solution. If you put the condition in the loop and break after it, it's never going to finish with the check.
$num = rand ( 1, 1000 );
$notPri = null;
for($check = 2; $check < $num; $check ++) {
if ($num % $check == 0) {
$notPri ++;
}
}
if ($neEpri == 0) {
echo $num . "
Prime!";
} else {
echo $num . "
Not a prime!";
}