1.3

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-largers x y z)
    (cond ((and (<= x y) (<= x z)) (sum-of-squares y z))
        ((and (<= y z) (<= y x)) (sum-of-squares x z))
        ((and (<= z x) (<= z y)) (sum-of-squares x y))
    )
)

(define (sum-of-squares x y)
    (+ (square x) (square y))
)

(define (square x) (* x x))
(sum-of-squares-of-largers 10 30 15)

results matching ""

    No results matching ""