Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

SICP Exercise 1.3

Name: Anonymous 2008-01-19 7:59

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 (ex3 x y z)
                     (cond
                       ((> y z x) ((define a x) (define b y) (+ (square a) (square b))))
                       ((> y x z) ((define a x) (define b y) (+ (square a) (square b))))
                       ((> z y x) ((define a x) (define b y) (+ (square a) (square b))))
                       ((> z x y) ((define a x) (define b y) (+ (square a) (square b))))
                       ((> x z y) ((define a x) (define b y) (+ (square a) (square b))))
                       ((> x y z) ((define a x) (define b y) (+ (square a) (square b)))))


I know I'm thinking about this the wrong way. My solution doesn't work.

Name: QBasic Master 2009-10-29 1:33

>>60
I like this one best.

I will now attempt to solve this in QBasic.

DECLARE FUNCTION MAX% (x%, y%)
DECLARE FUNCTION MIN% (x%, y%)
DECLARE FUNCTION SQUARE% (x%)

FUNCTION MAX% (x%, y%)
    IF x% > y% THEN MAX% = x% ELSE MAX% = y%
END FUNCTION

FUNCTION MIN% (x%, y%)
    IF x% < y% THEN MAX% = x% ELSE MAX% = y%
END FUNCTION

FUNCTION SQUARE% (x%)
    SQUARE% = x% * x%
END FUNCTION


' This is the main program
CLS

INPUT "Enter 3 integers: ", a%, b%, c%
PRINT
PRINT SQUARE%(MAX%(a%, b%)) + SQUARE%(MAX%(MIN%(a%, b%), c%))

END


Didn't run it in the interpreter yet but it should work to the best of my knowledge.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List