fork download
  1. sqrtEquation :: Double -> Double -> Double -> String
  2. sqrtEquation a b c
  3. | d < 0 = "No solutions"
  4. | d == 0 = (show x1)
  5. | d > 0 = (show x1) ++ " and " ++ (show x2)
  6. where d = (b*b - 4*a*c)
  7. x1 = ((-b + sqrt(d))/2*a)
  8. x2 = ((-b - sqrt(d))/2*a)
  9.  
  10.  
  11. main = do
  12. putStr "Input a:"
  13. a <- getLine
  14. putStr "Input b:"
  15. b <- getLine
  16. putStr "Input c:"
  17. c <- getLine
  18. let result = sqrtEquation (read a) (read b) $ read c
  19. putStrLn result
Success #stdin #stdout 0s 4776KB
stdin
16
0
0
stdout
Input a:Input b:Input c:0.0