Advertisement
Guest User

numeros-primos

a guest
May 20th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.28 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8.     <head>
  9.         <title>TODO supply a title</title>
  10.         <meta charset="UTF-8">
  11.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  12.     </head>
  13.     <body>
  14.         <div>Numeros primos até 1000</div>
  15.     <script>
  16.         var verificaPrimo = (numero) => {
  17.             var divisores = 0,
  18.             divisor = 1;
  19.             while(divisor <= numero) {
  20.                if (numero % divisor == 0) {
  21.                    divisores++  
  22.                }                
  23.                
  24.                if (divisores > 2) {
  25.                     return false;
  26.                 } else {
  27.                    
  28.                     if (divisor == numero) {
  29.                         return numero;
  30.                     }
  31.                 }
  32.                 divisor++;
  33.             }
  34.         }
  35.        
  36.         var x = 1; primos = [];
  37.        
  38.         while (x < 1000) {
  39.            if (verificaPrimo(x)) {
  40.                primos.push(x)
  41.            }
  42.            x+=2;
  43.        }
  44.        console.log(primos)
  45.    </script>        
  46.     </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement