Question

Write a Scheme function that takes a simple list of numbers as a parameter and returns...

Write a Scheme function that takes a simple list of numbers as a parameter and returns a list with the largest and smallest numbers in the input list.

Homework Answers

Answer #1

1). ANSWER :

GIVENTHAT :

To write a Scheme function that takes a simple list of numbers as a parameter and returns a list with the largest and smallest numbers in the input list.

code:

(define (max list)(cond((null? list) '())((null? (cdr list)) (car list))((> (car list) (max (cdr list))) (car list))(else (max (cdr list)))))

(define (min list)(cond((null? list) '())((null? (cdr list)) (car list))((< (car list) (min (cdr list))) (car list))(else (min (cdr list)))))

(define (minmax list) (cons (min list) (cons (max list) '())))

(display (minmax '(6 1 9 3 10 -6 2)))

Output :

(-6 10)

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
Define a function in Scheme which takes a list of numbers and a scalar and returns...
Define a function in Scheme which takes a list of numbers and a scalar and returns the rest of the list after the first occurrence of the scalar that was passed. An empty list should be returned if the value doesn't exist. For example, (list-past-scalar '(5 2 8 3 1 9 2 3) 3) #returns (1 9 2 3) (list-past-scalar '(37 18 38 65 90) 100) #returns ()
Write a function named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "i" replaced with the character "n python
Write a largestBelowValue(numbers, value) function that returns the largest number in the list numbers that is...
Write a largestBelowValue(numbers, value) function that returns the largest number in the list numbers that is smaller than value. Assume the numbers are always positive integers. Some example test cases (include these test cases in your program): >>>print(largestBelowValue([31, 5, 71, 53, 40, 17], 40)) 31 >>>print(largestBelowValue([31, 5, 71, 53, 40, 17], 41)) 40 returns None since no value is smaller than 2 in the list >>>print(largestBelowValue([31, 5, 71, 53, 40, 17], 2)) None
Write a Python function that takes a filename as a parameter and returns the string 'rows'...
Write a Python function that takes a filename as a parameter and returns the string 'rows' if a file was written row by row, and 'columns' if the file was written column by column. You would call the function with a command like filetype = myfunc(filename).
5.34 Write a function statement() that takes as input a list of floating-point numbers, with positive...
5.34 Write a function statement() that takes as input a list of floating-point numbers, with positive numbers representing deposits to and negative numbers representing withdrawals from a bank account. Your function should return a list of two floating-point numbers; the first will be the sum of the deposits, and the second (a negative number) will be the sum of the withdrawals. >>> statement([30.95, -15.67, 45.56, -55.00, 43.78]) [120.29, -70.67]
Write a Python function first_chars that takes one parameter, which is a nested list of strings....
Write a Python function first_chars that takes one parameter, which is a nested list of strings. It returns a string containing the first character of all of the non-empty strings (at whatever depth they occur in the nested list) concatenated together. Here are a couple of examples of how the function should behave when you're done: >>> first_chars(['Boo', 'is', 'happy', 'today']) 'Biht' >>>first_chars(['boo', 'was', ['sleeping', 'deeply'], 'that', 'night', ['as', ['usual']]]) 'bwsdtnau'
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)
Write a function that returns the largest element of an array? Your function should accept a...
Write a function that returns the largest element of an array? Your function should accept a 1-D array as an input and return the largest number. You may assume all numbers are integers. CODE IN C++ PLEASE
Write 2 C functions. One returns the maximum of 5 numbers. The other function, returns the...
Write 2 C functions. One returns the maximum of 5 numbers. The other function, returns the minimum of 5 numbers. In your main function, prompt the user to input 5 numbers and call the 2 functions above.
Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a...
Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a new array of that many double's initializes all elements to be 0 returns this array
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT