Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 29, 2019 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/55686e8068fd222268f3e019a99c27ef to your computer and use it in GitHub Desktop.
Save parzibyte/55686e8068fd222268f3e019a99c27ef to your computer and use it in GitHub Desktop.
/*
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