Created
July 29, 2019 22:43
-
-
Save parzibyte/55686e8068fd222268f3e019a99c27ef 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
/* | |
Par o impar en C, pero sin | |
usar divisiones ni operador módulo | |
@author parzibyte | |
Visita: parzibyte.me | |
*/ | |
#include <stdio.h> | |
int main() { | |
int numero; | |
printf("Escribe un número:\n"); | |
scanf("%d", &numero); | |
// Operación AND a nivel de bits | |
// Esto devolverá un 1 o un 0; y recordemos que | |
// un 1 se evalúa como true y un 0 como false | |
int resultado = numero & 1; | |
if (resultado) { | |
printf("El número %d es impar", numero); | |
} else { | |
printf("El número %d es par", numero); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment