All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Finding the maximum (Posted on 2004-04-21) Difficulty: 3 of 5
Using only standard math operators (+, -, *, /) and functions (absolute value, square root, powers, and so on), give a function that calculates MAX(A,B,C).

Alternate version, for programmers only: using any language (BASIC, C, Excel, whatever) find the maximum of A, B, and C, but be careful when writing the program, because you cannot use the "" key, for it's broken (thus writing things like IF A>B is impossible...) and you cannot use the "M" key either, for it's also broken (...and writing H=MAX(A,B) is also not possible.)

See The Solution Submitted by e.g.    
Rating: 4.0000 (5 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Lotsa IF's | Comment 13 of 16 |

I love Charlie's solution.  Absolutely beautiful.  I don't know if I ever would have thought of it.  Charlie's method clearly identifies the VALUE of the maximum.  But what if we want to know if the maximum is A vs B vs C?  Here's an algorithm that I believe does the job.  It is based on the fact that if X-Y=abs(X-Y) then X>=Y, if not then X<Y

IF A-B=abs(A-B)
   IF A-C=abs(A-C)
      THEN Return A
   ELSE Return C
ELSEIF  B-C=abs(B-C)
   THEN Return B
   ELSE Return C

ps, Penny, please email me, I have some programming questions, and you seem to be a guru.  Thanks.


Edited on April 22, 2004, 8:37 pm

Edited on April 22, 2004, 10:50 pm

Edited on April 22, 2004, 11:05 pm
  Posted by Larry on 2004-04-22 20:27:19

Please log in:
Remember me:
Sign up! | Forgot password

Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Copyright © 2002 - 2020 by Animus Pactum Consulting. All rights reserved. Privacy Information