+ 5
How to find a number is prime or composite
in PHP
4 ответов
+ 14
/*
isPrime(p){
if (p<=1) return false;
for (a = 2; a <= p/2; a++) {
if (p % a == 0){
return false;
break;
}
}
return true;
}
*/
if (p!=1&&!isPrime (p)) System.out.print(composite);
+ 3
thanks@toni
+ 1
For prime numbers
function isPrime($p){
for ($a = 2; $a <= $p/2; $a++) {
if ($p % $a == 0){
return false;
}
}
return true;
}
+ 1
You can check this https://code.sololearn.com/wtRgMCG7xbxb/#php