10. Write a function in HASKELL
howManyBelowAverage that returns how many of three integer inputs are below its average value. (Hint: utilize the averageThree function.) howManyBelowAverage :: Integer -> Integer -> Integer -> Integer
averageThree :: Integer -> Integer -> Integer -> Float
AverageThree x y z = fromInteger(x+y+z) / 3.0
Can someone please help me solve the howManyBelowAverage function?
Haskell complete code is provided below. The required function is highlighted.If any doubt please comment below.
Haskell Code:
averageThree :: Integer -> Integer -> Integer -> Float
--- Given function
averageThree x y z = fromInteger(x+y+z) / 3.0
howManyBelowAverage :: Integer -> Integer ->
Integer -> Integer -- counting numbers below average
howManyBelowAverage a b c = (if (fromInteger a < averageThree a
b c)then 1 else 0)
+ (if (fromInteger b < averageThree a b c) then 1 else 0)
+ (if (fromInteger c < averageThree a b c) then 1 else
0)
main = do
putStrLn "Count of numbers below Average:"
print(howManyBelowAverage 40 10 10) --function call
Output:
Get Answers For Free
Most questions answered within 1 hours.