开发者

Haskell quadratic equation root

开发者 https://www.devze.com 2023-04-13 08:28 出处:网络
Haskell program which shows the two roots and in the case that the equation has no real roots or has all values as roots should return zero.

Haskell program which shows the two roots and in the case that the equation has no real roots or has all values as roots should return zero.

functionRoot :: Float -> Float -> Float -> (Float,Float)        
functionRoot a b c = if d < 0 then error "0" else (x, y)
                        where x = e + sqrt d / (2 * a)
                        y = e - sqrt d / (2 * a)
            开发者_C百科            d = b * b - 4 * a * c
                        e = - b / (2 * a)

ERROR: file:.\roots.hs:4 - Syntax error in input (unexpected symbol "y") any thought?


You need to indent definitions under where further.

functionRoot a b c = if d < 0 then error "0" else (x, y)
                        where
                          x = e + sqrt d / (2 * a)
                          y = e - sqrt d / (2 * a)
                          d = b * b - 4 * a * c
                          e = - b / (2 * a)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号