Last active
September 21, 2023 12:32
-
-
Save lrlucena/4576140 to your computer and use it in GitHub Desktop.
Lista de Exercícios 5 da disciplina de Programação de Computadores
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 e mostre se ele é múltiplo de 7. | |
puts "Digite um número: " | |
x = gets.to_i | |
if x%7==0 then | |
puts "#{x} é multiplo de 7." | |
else | |
puts "#{x} não é multiplo de 7." | |
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 um número e mostre se ele é positivo. | |
puts "Digite um número: " | |
x = gets.to_i | |
if x>0 then | |
puts "#{x} é positivo." | |
else | |
puts "#{x} não é positivo." | |
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 dois números e informe se eles são iguais. | |
puts "Digite dois números: " | |
x = gets.to_i | |
y = gets.to_i | |
if x==y then | |
puts "Os números são iguais." | |
else | |
puts "#{x} e #{y} não são iguais." | |
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 dois números e mostre o maior. | |
puts "Digite dois números: " | |
x = gets.to_i | |
y = gets.to_i | |
maior = if x>y then x else y end | |
puts "O maior número é #{maior}." |
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 dois nomes e mostre o que contém | |
# maior quantidade de caracteres. | |
puts "Digite dois nomes: " | |
x = gets.chomp | |
y = gets.chomp | |
maior = if x.length > y.length then x else y end | |
puts "#{maior} é o nome que contém mais caracteres." |
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 e informe se ele é | |
# positivo ou negativo | |
print "Digite um número: " | |
x = gets.to_i | |
sinal = if x>0 then "positivo" elsif x<0 then "negativo" else "zero" end | |
puts "#{x} é #{sinal}." |
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 que corresponde | |
# a um ângulo e informe em qual quadrante este ângulo se encontra. | |
print "Digite um ângulo: " | |
angulo = gets.to_i % 360 | |
quadrante = | |
if angulo < 90 then "primeiro" | |
elsif angulo < 180 then "segundo" | |
elsif angulo < 270 then "terceiro" | |
else "quarto" end | |
puts "O ângulo #{angulo} fica no #{quadrante} quadrante." |
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úmeros inteiro que corresponde | |
# a um ângulo e informe em qual quadrante este ângulo se encontra | |
# e quantas voltas ele dá (360 graus = uma volta). | |
print "Digite um ângulo: " | |
angulo_entrada = gets.to_i | |
angulo = angulo_entrada % 360 | |
voltas = angulo_entrada / 360 | |
quadrante = | |
if angulo < 90 then "primeiro" | |
elsif angulo < 180 then "segundo" | |
elsif angulo < 270 then "terceiro" | |
else "quarto" end | |
puts "O ângulo #{angulo} dá #{voltas} voltas e fica no #{quadrante} quadrante." |
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 dois números e informe se o maior é | |
# múltiplo do menor | |
print "Digite o primeiro número: " | |
x = gets.to_i | |
print "Digite o segundo número: " | |
y = gets.to_i | |
# menor, maior = if x<y then [x,y] else [y,x] end | |
menor = if x<y then x else y end | |
maior = if x>y then x else y end | |
if maior%menor==0 then | |
puts "#{maior} é múltiplo de #{menor}." | |
else | |
puts "#{maior} não é múltiplo de #{menor}." | |
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
# Escreva um programa leia dois nomes de times de futebol, a | |
# quantidade de gols do primeiro time, a quantidade de gols do | |
# segundo time e mostre o nome do time vencedor da partida | |
puts "Digite os nome dos dois times" | |
nome1, nome2 = gets.chomp, gets.chomp | |
print "Digite a quantidade de gols do time #{nome1}: " | |
gols1 = gets.to_i | |
print "Digite a quantidade de gols do time #{nome2}: " | |
gols2 = gets.to_i | |
vencedor = | |
if gols1 > gols2 then nome1 | |
elsif gols1 < gols2 then nome2 | |
else "empate" end | |
puts "O vencedor foi o time #{vencedor}." |
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 | |
# Brincadeira do ímpar ou par: escreva um programa que leia dois | |
# nomes e dois valores inteiros, que correspondem ao que cada um | |
# colocou, e informe quem ganhou o “ímpar ou par”. | |
print "Digite os nome jogador par: " | |
jogador_par = gets.chomp | |
print "Digite os nome jogador ímpar: " | |
jogador_impar = gets.chomp | |
print "Digite o número de #{jogador_par}: " | |
n1 = gets.to_i | |
print "Digite o número de #{jogador_impar}: " | |
n2 = gets.to_i | |
resultado = if (n1+n2)%2==0 then "Par" else "Ímpar" end | |
vencedor = if resultado=="Par" then jogador_par else jogador_impar end | |
puts "#{resultado}, o vencedor foi #{vencedor}." |
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 real e faça o | |
# arredondamento para inteiro. Se a parte fracionária for maior do que | |
# 0.5 o arredondamento deve ser feito para o próximo inteiro. | |
print "Digite um número real: " | |
real = gets.chomp | |
inteiro = real.to_i | |
fracao = real.to_f - inteiro | |
redondo = inteiro + if fracao > 0.5 then 1 else 0 end | |
puts "#{real} arredondado para inteiro é #{redondo}." |
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 4 números e mostre o maior. | |
puts "Digite 4 números" | |
a = gets.to_i | |
b = gets.to_i | |
c = gets.to_i | |
d = gets.to_i | |
maior = | |
if a>b and a>c and a>d then a | |
elsif b>c and b>d then b | |
elsif c>d then c | |
else d end | |
puts "O maior número é #{maior}." |
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 dois nomes e informe se os mesmos | |
# são iguais. Além de informar se os nomes são iguais ele deve | |
# informar se há diferenças na digitação de letras maiúsculas/ | |
# minúsculas. | |
puts "Digite dois nomes" | |
nome1 = gets.chomp | |
nome2 = gets.chomp | |
resposta = | |
if nome1==nome2 then | |
"iguais" | |
elsif nome1.upcase==nome2.upcase then | |
"iguais mas há diferenças de digitação" | |
else | |
"diferentes" | |
end | |
puts "Os nomes são #{resposta}." |
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 3 números inteiros e mostre-os em | |
# ordem crescente. | |
puts "Digite 3 números" | |
a = gets.to_i | |
b = gets.to_i | |
c = gets.to_i | |
maior = if a>b and a>c then a elsif b>c then b else c end | |
menor = if a<b and a<c then a elsif b<c then b else c end | |
meio = a + b + c - maior - menor | |
puts "Os números em ordem crescente: #{menor}, #{meio}, #{maior}." |
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 e mostre se ele é igual a 10. | |
puts "Digite um número: " | |
x = gets.to_i | |
if x==10 then | |
puts "O valor digitado foi 10." | |
else | |
puts "O valor digitado não foi 10." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Escreva um programa que peça ao usuário um número e exiba se ele é múltiplo de
3 ou 5.