Hello everyone,
How can I define a procedure that takes three numbers as arguments and
returns the sum of the squares of the two larger numbers ?
Thanks a lot
--
Yours truly,
Pat
Sent via Deja.com http://www.deja.com/
Before you buy.
There are several ways to do this, the easyest being...
(defun sum_sq (a b c)
(let ((temp (sort (list a b c) #'>)))
(+ (square (car temp))(square (cadr temp)))))
That should do it
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
* patcyr wrote:
> Hello everyone,
> How can I define a procedure that takes three numbers as arguments and
> returns the sum of the squares of the two larger numbers ?
int sum_of_two_largest(int x, y, z)
{
int l1; l2;
if (x >= y) {
l1 = x;
l2 = (y >= z) ? y : z;
} else {
l1 = y;
l2 = (x >= z) ? x : z;
}
return l1 *l1 + l2 * l2;
}
······@my-deja.com writes:
> How can I define a procedure that takes three numbers as arguments and
> returns the sum of the squares of the two larger numbers ?
(defun
the-sum-of-the-squares-of-the-two-largest-numbers-in-a-set-of-three
(first-number second-number third-number) (+ (/ (+ (* (- first-number
second-number)(- first-number second-number)) (* (+ first-number
second-number)(+ first-number second-number)) ) 2) (* (+ third-number
(min first-number second-number third-number))(- third-number (min
first-number second-number third-number)))))
Stig Hemmer,
Jack of a Few Trades.
From: Arne Knut Roev
Subject: Re: Simple program question
Date:
Message-ID: <FoJouy.4oE@online.no>
······@my-deja.com wrote:
> How can I define a procedure that takes three numbers as arguments and
> returns the sum of the squares of the two larger numbers ?
Chapter 1, exercise 1.3, page 21, of the "Structure and Interpretation of
Computer Programs", by Abelson, Sussman (_and_ Julie Sussman).
Assuming your instructor is using the second edition, of course.
However, I do think that your instructor will expect to see _Scheme_ code
for this function, and since you chose to post in c.l.lisp instead of
c.l.scheme, you should at least have mentioned this...
--
Arne Knut Roev <······@online.no> Snail: N-6141 ROVDE, Norway
=
The Gates of Hell shall not prevail:
Darkness now; then Light!