cañangasñangas Posted May 28, 2013 Report Share Posted May 28, 2013 (edited) 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 May 28, 2013 by cañangasñangas Link to comment Share on other sites More sharing options...
bombero_7 Posted June 17, 2013 Report Share Posted June 17, 2013 ????? Link to comment Share on other sites More sharing options...
cañangasñangas Posted June 17, 2013 Author Report Share Posted June 17, 2013 ????? porfavor si tienes algo que acotar que sea sobre el tema y no un simple "???" a la proxima advertencia PD: no te advierto porque el tema en cuestion sea mio, sino porque en realidad no tiene ni contenido tu mensaje... Link to comment Share on other sites More sharing options...
shagof Posted July 27, 2014 Report Share Posted July 27, 2014 se puede mejorar un poco el tiempo de ejecucion haciendo el ciclo hasta la raiz cuadrada de n..... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now