Skip to content

Commit

Permalink
Bitwise implementation of odd or even
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroarthur committed Mar 17, 2011
1 parent 151e4a6 commit 2b514fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 11 additions & 1 deletion math/even/even.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Encontrando números Pares
Autor:
???
Colaborador:
Colaboradores:
Filipe Saraiva (filip.saraiva@gmail.com)
Pedro Arthur Duarte (pedroarthur.jedi@gmail.com)
Tipo:
math
Descrição:
Expand Down Expand Up @@ -50,6 +51,15 @@ void numerosPares(int num){
printf("\n");
}

/* Via aritimética binária (maneira convencional) */
void numerosPares_2(int num) {
int contador;

for (contador = 0 ; contador <= num ; contador++)
if ((contador & 1) == 0)
printf("%d ", contador);
}

// Função main
int main(){

Expand Down
13 changes: 10 additions & 3 deletions number-theory/odd-even/odd-even.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@
Par ou impar
Autor:
?
Colaborador:
Geraldo Neto email:glnetinho@hotmail.com
Colaboradores:
Geraldo Neto email (glnetinho@hotmail.com)
Prdro Arthur Duarte (pedroarthur.jedi@gmail.com)
Tipo:
number-theory
Descricao:
Verifica se os números são impares ou pares.
Complexidade:
?
O(n), Através de operação módulo
O(1), Através de operador binário
Dificuldade:
facil
*/

#include <stdio.h>

/*
Macro: retorna 1 se o número for impar ou 0 caso contrário
*/
#define oddOrEven(a) ((a) & 1)

void main(void)
{
int v[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
Expand Down

0 comments on commit 2b514fc

Please sign in to comment.