The function required by the topic requires the following three things to be done:
- Write a function that accepts three numbers as a parameter
- Determine the larger of the three numbers in two
- Calculates the sum of squares of a larger two numbers (the sum of the squares of two numbers)
We're going to do these three tasks from the back to the next step.
CSDN No Lisp. It's tagged with python.
#lang racket;; SICP 1.3;; Try 1 (define (square x) (* x x)) (define (sum x y) (+ (square x) (square y))) (define (sum-largest x y z) ( cond (= (min x y z) x (sum y z)) (( = (min x y z) (sum x z)) ((= (min x y z)) (sum x y))) ; Try 2 (define (Largest-three x y z) ( if (>= x y) ( sum x (if (>= y z) y z)) (Sum y (if (>= x z) x z))) ;; Testing 1 (sum-largest 2 3 6) (Sum-largest 5 8 12); Testing 2 (Largest-three 4 8 75)
SICP1.3 MIT (CLT) scheme implementation (LISP)