Question

10. Write a function in HASKELL howManyBelowAverage that returns how many of three integer inputs are...

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?

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please do in Haskell programming language. Write a function intLog of type Integer -> Integer that...
Please do in Haskell programming language. Write a function intLog of type Integer -> Integer that returns the exponent of the largest power of 2 less than its integer argument. Your function need not behave well if the parameter is negative. Try your function on intLog 468.
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them.         [0.5 mark] (BY USING C PROGRAM)
float sum( float x, float y, float z ) ​program in c++
Here are the function prototypes for your homeworkWrite out the actual functions themselves Also, create a main function that demonstrates that all four functions work The user should be able to provide four values to your program (three floats and an int) Your program should then use your four new functions and also display the results to the user NONE of these functions should print values themselvesfloat sum( float x, float y, float z ); // returns the sum of three floatsfloat mean( float...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
The function named myRandomNum that returns a random integer in the range [1, 100] is defined...
The function named myRandomNum that returns a random integer in the range [1, 100] is defined as follows: int myRandomNum () { return rand()%100 + 1; } Now, write a program (code fragment) that repeatedly generates and prints random integers in the range [1, 100]. The program must stop when the absolute value of the difference between successive printed values is less than 5. Two sample output is given to help you understand the problem: 1. The program can possibly...
Instructions Write a Java code Your goal is to take N integer inputs from the user...
Instructions Write a Java code Your goal is to take N integer inputs from the user -- N's value will be given by the user as well. You can assume the user provides a valid value for N, i.e., >0. Store the input integers in an array of size N in the order they are provided. These tasks should be done in the main() method. Create a new method called checkArray() that will take the previously created array as input...
##4. What will the following program display? ##def main(): ## x = 1 ## y =...
##4. What will the following program display? ##def main(): ## x = 1 ## y = 3.4 ## print(x, y) ## first printing ## change_us(x, y) ## print(x, y) ##second printing ## ##def change_us(a, b): ## a = 0 ## b = 0 ## print(a, b) ## ##main() ## ##Yes, yes, main() displays ##1 3.4 ##0 0 ##1 3.4 ## The question is: why x and y are still the same while the second printing of (x,y)? ## It seems...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs and compares the character by character. If the two strings are exactly same it returns 0, otherwise it returns the difference between the first two dissimilar characters. You are not allowed to use built-in functions (other than strlen()) for this task. The function prototype is given below: int compare_strings(char * str1, char * str2); Task 3: Test if a string is subset of another...
Write the function most_factors(numbers) that returns the integer from the list numbers that has the most...
Write the function most_factors(numbers) that returns the integer from the list numbers that has the most factors (divisors without remainder). For example: >>> most_factors([5,10,16,20,25]) 20 # because 20 has the most factors of any of these numbers # 6 factors, i.e., [1, 2, 4, 5, 10, 20] >>> most_factors([1, 2, 3, 4, 5]) 4 # because 4 has the most factors of any of these numbers # 3 factors, i.e., [1, 2, 4] Hints: For each element in numbers, call...
Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on...
Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on how many matching numbers are provided by a player. The player provides three different integers between 1 and 10. If there is a match of all 3 numbers, the winning $ 1000. If there is a match with 2 numbers, the winning $ 10. If there is a match with 1 number, the winning $ 1. With no match, the winning is $0. Write...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT