SICP exercise 1.3
- Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
bigger of two numbers
(define (bigger-of-two x y)
(if (> x y) x
y)
biggest of three numbers
(define (biggest-of-three x y z)
(if (> (bigger-of-two x y) z) (bigger-of-two x y)
z)
)
medium of three numbers
(define (medium-of-three x y z)
(cond ((= (biggest-of-three x y z) x) (bigger-of-two y z))
((= (biggest-of-three x y z) y) (bigger-of-two x z))
((= (biggest-of-three x y z) z) (bigger-of-two y x)))
)
square of number
(define (square x) (* x x))
sum of two squares
(define (sum-of-squares x y)
(+ (square x) (square y))
)
sum of squares of the two larger numbers
(define (fun x y z)
(sum-of-squares (biggest-of-three x y z) (medium-of-three x y z))
)