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.
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)
Get Answers For Free
Most questions answered within 1 hours.