Last active
December 17, 2015 17:54
-
-
Save lrlucena/4637721 to your computer and use it in GitHub Desktop.
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
# encoding: utf-8 | |
# Escreva um programa que leia 10 números e mostre-os ordenados | |
puts "Digite 10 números" | |
numeros = 10.times.map do gets.to_i end | |
puts numeros.sort |
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
# encoding: utf-8 | |
# Escreva um programa que leia um número inteiro n. Depois leia n | |
# números inteiros e mostre-os ordenados. | |
print "Quantos números: " | |
n = gets.to_i | |
puts "Digite os #{n} números" | |
numeros = n.times.map do gets.to_i end | |
puts numeros.sort |
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
# Escreva um programa que leia 8 nomes e mostre-os em ordem | |
# alfabética | |
puts "Digite 8 nomes" | |
nomes = 8.times.map do gets.chomp end | |
puts nomes.sort |
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
# Qual a diferença entre exibir um array usando puts e print? | |
x = [1,2,3,4,5] | |
print x | |
puts "" | |
puts x |
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
# encoding: utf-8 | |
# Leia 5 números inteiros exiba-os ordenados do maior para o | |
# menor. | |
puts "Digite 5 números" | |
numeros = 5.times.map do gets.to_i end | |
puts numeros.sort.reverse |
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
# encoding: utf-8 | |
# Leia os dois primeiros números de um array de inteiros e depois | |
# calcule os 8 números seguintes do array. A regra é que os demais | |
# elementos são calculados somando os dois anteriores. Exiba o | |
# array usando print. | |
puts "Digite os dois primeiros números da sequência" | |
a = gets.to_i, gets.to_i | |
for i in 2..9 | |
a[i] = a[i-1] + a[i-2] | |
end | |
print a |
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
# encoding: utf-8 | |
# Escreva um programa que leia um array de 20 notas, depois leia | |
# uma nota. O programa deve então mostrar se a nota lida está entre | |
# as 10 melhores notas ou as 10 piores notas. | |
puts "Digite as vinte notas" | |
notas = 20.times.map do gets.to_i end | |
puts "Digite a nota" | |
nota = gets.to_i | |
notas_em_ordem = notas.sort | |
situacao = | |
if nota<notas_em_ordem[10] then | |
"piores" | |
else | |
"melhores" | |
end | |
puts "A nota está entre as 10 #{situacao} notas." |
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
# encoding: utf-8 | |
# Escreva um programa leia n números inteiros e armazene-os em | |
# um array. O programa deve então verificar se a soma dos valores | |
# do primeiro e do último elemento é um índice válido do array | |
# (encontra-se no array). Se sim o programa deve mostrar o valor | |
# contido nesse índice, se não o programa mostra “Nao encontrado”. | |
n = 4 | |
numeros = n.times.map do gets.to_i end | |
soma = numeros.first + numeros.last | |
if soma>=0 and soma<numeros.size then | |
puts numeros[soma] | |
else | |
puts "Não encontrado" | |
end |
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
# encoding: utf-8 | |
# Escreva um programa que leia 10 números e mostre-os na ordem | |
# em que foram lidos. | |
puts "Digite 10 números" | |
numeros = 10.times.map do gets.to_i end | |
puts numeros |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment