Advertisement
kinhoSilva

Numeros primos PHP

Mar 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Numeros randomicos!
  5. * @param min e max
  6. * @author Henrique Silva
  7. */
  8. $number_rand = rand(1, 100);
  9.  
  10. /**
  11. *   Array para armazenar os divisores
  12. */
  13. $divisores = [];
  14.  
  15. /**
  16. * Loop para armazenar os divisores
  17. */
  18. for($i=1; $i <= $number_rand; $i++){
  19.  
  20.     $result_div = $number_rand / $i;
  21.     if(is_int($result_div)){
  22.         $divisores[] = $result_div;
  23.     }
  24. }
  25.  
  26. /**
  27. * Verificar si o numero é dividido apenas por 2 divisores!
  28. */
  29. if(count($divisores) == 2){
  30.     echo "O numero {$number_rand} é primo!";
  31. }else{
  32.     echo "O numero {$number_rand} não é primo!";
  33. }
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement