Created
July 20, 2016 21:13
-
-
Save mateusmpa/363b0949159d5f00aecb302db81c2eb2 to your computer and use it in GitHub Desktop.
treinamento ruby loca
This file contains hidden or 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
| Ex1. | |
| puts "Insira um número:" | |
| pair = (Integer(gets.strip) % 2) == 0 | |
| puts "É #{pair ? 'par' : 'ímpar'}!!" | |
| Ex2. | |
| ingredients = { | |
| 2 => 'açucar', | |
| 3 => 'trigo', | |
| 4 => 'margarina', | |
| 3 => 'ovos', | |
| 1 => 'leite', | |
| 1 => 'fermento' | |
| } | |
| ingredients.each {|key, value| puts "#{key} quantidade de #{value}"} | |
| puts "Insira uma proporção:" | |
| proportion = Integer(gets.strip) | |
| ingredients.each {|key, value| puts "#{key * proportion} quantidade de #{value}"} | |
| Ex3. | |
| puts "Insira o começo da tabuada:" | |
| start = Integer(gets) | |
| puts "Insira o final da tabuada:" | |
| finish = Integer(gets) | |
| if start <= finish | |
| for i in start..finish | |
| for j in 1..10 | |
| puts "#{i} * #{j} = #{i*j}" | |
| end | |
| puts "---" | |
| end | |
| else | |
| puts "O valor inicial precisa ser inferior ao final!!" | |
| end | |
| puts "Insira um número:" | |
| number = Integer(gets.strip) | |
| if number == 0 | |
| puts 'não é primo' | |
| elsif number == 1 | |
| puts 'é primo' | |
| else | |
| for i in (2..number-1) | |
| puts "não é primo" if (number % i) == 0 then block | |
| end | |
| puts "é primo" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment