Skip to content

Instantly share code, notes, and snippets.

@asonnleitner
Created February 16, 2022 06:30
Show Gist options
  • Save asonnleitner/f577cbc06d0ce8c0f8f2b8538e33eba9 to your computer and use it in GitHub Desktop.
Save asonnleitner/f577cbc06d0ce8c0f8f2b8538e33eba9 to your computer and use it in GitHub Desktop.
puts "Zadejte a, b, c"
a = gets.chomp.to_f # konverze na float
b = gets.chomp.to_f
c = gets.chomp.to_f
# Výpočet diskriminantu
DIS = b**2 - 4 * a * c
puts "Diskriminant je #{DIS}"
if DIS > 0
x1 = (-b + (DIS**0.5)) / (2 * a)
# nebo (-b + Math.sqrt(DIS)) / (2 * a)
x2 = (-b - (DIS**0.5)) / (2 * a)
# nebo (-b - Math.sqrt(DIS)) / (2 * a)
puts "x1: #{x1}, x2: #{x2}"
elsif DIS == 0
x = -b / (2 * a)
puts "x = #{x}"
else
puts "Rovnice nemá řešení"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment