1

link: Modus Operandi. Formulae for Maximum and Minimum of two numbers with a + b and $|a - b|$

And obviously it return first number all the time if i do it as mention for 3 numbers $1/2 ( add \text{ } 3 ) + ( sub \text{ } 3 )$ .

or even I try to calculate 2 numbers it just return fist number.

Is there any way I can find maximum from 3 numbers.

I do not have math background am programmer so excuse if you find it stupid but I seriously want to do it using a formula.

I can do it by natural way by iterating over remaining number but that will cost time of 3! or N!.

So please do share if you can point to me in a way so I do it mathematically.

  • maximum of three numbers – Satish Ramanathan Oct 02 '17 at 06:59
  • I think you can use recursion for three and above numbers like for three numbers first we can find $c = $maximum of two numbers and next maximum between $c $ and the last number – BAYMAX Oct 02 '17 at 07:04
  • It will not cost you N!, just N-1. Unless you know how |a-b| is implemented, there's no reason to believe that a formula is better than a conditional if-then-else. If you really want to do recursively: max(x_1,x_2,...,x_n)=max(x_1,max(x_2,...x_n)). – user334639 Oct 02 '17 at 07:05

1 Answers1

2

Hint: $$max\{ a,b,c\}=max\{max\{a,b\} ,c\}$$ It cost less time

Khosrotash
  • 24,922