Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 711 Bytes

README.md

File metadata and controls

26 lines (17 loc) · 711 Bytes

描述

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

定义一个过程,该过程将三个数字作为参数,并返回两个较大数字的平方和。

解答

这里的难点在于找出三个数中较大的两个,我这里的思路主要是先找出最小的那个,如果a <= b <= c那么a就是最小的

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

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

(define (sum-of-max a b c)
  (cond ((<= a b c) (sum-of-squares b c))
        ((<= b c a) (sum-of-squares c a))
        ((<= c a b) (sum-of-squares a b))
  )
)

(sum-of-max 1 2 3)

13