Exercise 1.3

Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.

(define (sum-of-squares-of-two-largest x y z)
  (cond ((and (< x y) (< x z)) (+ (* y y) (* z z)))
        ((and (< y x) (< y z)) (+ (* x x) (* z z)))
        (else (+ (* x x) (* y y)))))

(sum-of-squares-of-two-largest 1 2 3) ;13

For arguments 1, 2, 3, the procedure will add \(2^2=4\) and \(3^2=9\), returning 13.

Back to exercises