Created
September 17, 2012 02:10
-
-
Save gtcarlos/3735190 to your computer and use it in GitHub Desktop.
Função para diferenciar números pares e impares sem usar divisão
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
def par_impar(num) | |
if (-1)**num == 1 | |
print "#{num}: par\n" | |
else | |
print "#{num}: impar\n" | |
end | |
end | |
par_impar(1) | |
par_impar(2) | |
par_impar(1234) | |
par_impar(1233) | |
par_impar(20) | |
par_impar(21) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment