Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang 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))
- ;sum of squares
- (define (sumOfSquares a b) (+ (square a) (square b)))
- (define (sumTwoLargestSquares op1 op2 op3)
- ;compare the three numbers and get the largest number
- (define (largestNumber x y z)
- (cond((and(> x y) (> x z)) x)
- ((and(> y x) (> y z)) y)
- ((and(> z x) (> z y)) z)))
- ;compare the three numbers and get the second largest number
- (define (secondLargestNumber x y z)
- (cond((and(> x y) (< x z)) x)
- ((and(> y x) (< y z)) y)
- ((and(> z x) (< z y)) z)))
- ;return the sum of the squares of the two
- (sumOfSquares largestNumber secondLargestNumber))
- (sumTwoLargestSquares 1 2 3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement