Thursday, June 17, 2010

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.

(define (square x)  
(* x x))

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

(define (sum-square-two-largest x y z)
(cond [(and (> x z) (> y z)) (sum-of-squares x y)]
[(and (> x y) (> z y)) (sum-of-squares x z)]
[else (sum-of-squares y z)]))

No comments:

Post a Comment