Created
December 18, 2012 15:40
-
-
Save anonymous/4329088 to your computer and use it in GitHub Desktop.
Respostas dos Exercícios do dia 17/12/2012
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
# Questao 1 | |
x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 | |
# Questao 2 | |
media = (7.7 + 8.35) / 2.0 | |
# Questao 3 | |
nota1 = 9.0 | |
nota2 = 8.0 | |
media_parcial = (nota1*2.0 + nota2*3.0)/5.0 | |
# Questao 4 | |
x = 73623 | |
digito = x % 10 | |
# Questao 5 - Usando outras variaveis | |
x = 1234 | |
milhar = x / 1000 % 10 | |
centena = x / 100 % 10 | |
dezena = x / 10 % 10 | |
unidade = x / 1 % 10 | |
x_invertido = unidade * 1000 + dezena * 100 + centena * 10 + milhar | |
# Questao 5 - Usando apenas x | |
x = 1234 | |
x_invertido = (x / 1 % 10) * 1000 + | |
(x / 10 % 10) * 100 + | |
(x / 100 % 10) * 10 + | |
(x / 1000 % 10) | |
# Questao 6 - Usando uma variável auxiliar (aux) | |
x = 10 | |
y = 20 | |
aux = x | |
x = y | |
y = aux | |
# Questao 6 - Usando apenas x e y | |
x = 10 | |
y = 20 | |
x = x + y | |
y = x - y | |
x = x - y | |
# Questao 6 - Usando atribuicao simultanea | |
x = 10 | |
y = 20 | |
x,y = y,x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment