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 cencrypt() function that takes a arbitrary length string and an integer as inputs and...
Write a cencrypt() function that takes a arbitrary length string and an integer as inputs and returns a string as output. The cencrypt() function you write in lab today needs to work on strings that contain upper-case letters, lower-case letters, or both. The output string should be all upper-case letters. (The Romans of Caesar's time used only what today we call upper-case letters.) So a call to cencrypt("Caesar", 1) should return (return not print) the string “DBFTBS” and a call...
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...
Please write a java program Instructions Your goal is to take N integer inputs from the...
Please write a java program Instructions 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...
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...
##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...
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...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT