brewersfan1976

quadratic_equation.rb

Jun 16th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.61 KB | None | 0 0
  1. def quadraticEquation(a, b, c)
  2.     output = Array.new
  3.    
  4.     if (b ** 2) - (4 * a * c) < 0 then
  5.        return output
  6.     end
  7.    
  8.     if (b ** 2) - (4 * a * c) == 0 then
  9.        output[0] = -(b / (2 * a))
  10.        return output
  11.     end
  12.        
  13.     temp = 0
  14.     temp = (b ** 2) - (4 * a * c)
  15.     temp = Math.sqrt(temp)
  16.     temp = -b + temp
  17.     temp = temp / (2 * a)
  18.     x = temp
  19.     output[0] = x
  20.        
  21.     temp = 0
  22.     temp = (b ** 2) - (4 * a * c)
  23.     temp = Math.sqrt(temp)
  24.     temp = -b - temp
  25.     temp = temp / (2 * a)
  26.     x = temp
  27.     output[1] = x
  28.        
  29.     return output.sort
  30. end
Advertisement
Add Comment
Please, Sign In to add comment