Jump to content

Recommended Posts

funcion para saber si un numero es primo

function is_primo($n){
    if($n == 1){ return false; }
    for($i=1;$i<=$n;$i++){
        if($n%$i == 0){
        $aux++;
        }
        
        if($aux > 2){
        return false;
        }
    }
return true;
}

lo unico que tienes que hacer es

$num = ;//numero perteneciente a los naturales...
if(is_primo($num)){
echo $num." es primo";
}
else{
echo $num." no es primo";
}
Edited by cañangasñangas
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...