Created
September 27, 2019 01:21
-
-
Save parzibyte/d51e70df857bd57a0e2d58b7d1cfcdf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Número primo en C++ o CPP | |
https://parzibyte.me/blog | |
*/ | |
bool esPrimo(int numero) { | |
// Casos especiales | |
if (numero == 0 || numero == 1 || numero == 4) return false; | |
for (int x = 2; x < numero / 2; x++) { | |
if (numero % x == 0) return false; | |
} | |
// Si no se pudo dividir por ninguno de los de arriba, sí es primo | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment