Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def quadraticEquation(a, b, c)
- output = Array.new
- if (b ** 2) - (4 * a * c) < 0 then
- return output
- end
- if (b ** 2) - (4 * a * c) == 0 then
- output[0] = -(b / (2 * a))
- return output
- end
- temp = 0
- temp = (b ** 2) - (4 * a * c)
- temp = Math.sqrt(temp)
- temp = -b + temp
- temp = temp / (2 * a)
- x = temp
- output[0] = x
- temp = 0
- temp = (b ** 2) - (4 * a * c)
- temp = Math.sqrt(temp)
- temp = -b - temp
- temp = temp / (2 * a)
- x = temp
- output[1] = x
- return output.sort
- end
Advertisement
Add Comment
Please, Sign In to add comment