SICP exercise 1.03

From Drewiki

Jump to: navigation, search

Problem

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

Solution

We can use the compound procedures square, sum-of-squares and >= that were defined earlier in sections 1.1.4 and 1.1.6 of the text:

 

Here's a procedure that implements a solution to the problem:

 

Tests

To test the solution, we can pick 3 distinct arguments and try all their permutations:

 

Output:

25


 

Output:

25


 

Output:

25


 

Output:

25


 

Output:

25


 

Output:

25
Personal tools