📁
SICP
  • README
  • Building Abstractions With Procedures
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
Powered by GitBook
On this page

Was this helpful?

  1. Building Abstractions With Procedures

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)
Previous2Next4

Last updated 4 years ago

Was this helpful?