(11C) Finding biggest of 3 integers - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (11C) Finding biggest of 3 integers (/thread-11613.html) |
(11C) Finding biggest of 3 integers - Gamo - 10-20-2018 05:41 AM Program to find the biggest number of 3 integers. Procedure: f [USER] n1 [ENTER] n2 [ENTER] n3 [E] Example: 1, 3 and 2 1 [ENTER] 3 [ENTER] 2 [E] display 3 Biggest number is 3 --------------------------------------- 14, 10 and 8 14 [ENTER] 10 [ENTER] 8 [E] display 14 -------------------------------------- -4, -3 and -6 4 [CHS] [ENTER] 3 [CHS] [ENTER] 6 [CHS] [E] display -3 ------------------------------------- FIX 4 0.9987, 0.9990 and 0.9989 ,9987 [ENTER] ,9990 [ENTER] ,9989 [E] display 0.9990 Program: Finding biggest of 3 integers Code:
Gamo RE: (11C) Finding biggest of 3 numbers - Dieter - 10-20-2018 10:48 AM (10-20-2018 05:41 AM)Gamo Wrote: Program to find the biggest number of 3 integers. Of any three numbers, not only integers. Gamo, do you remember the following sequence? With two numbers in X and Y, X≤Y? X<>Y checks if X is the smaller of the two. If it is, both are swapped. So this sequence always returns the larger number in X and the smaller one in Y. Likewise, X>Y? X<>Y returns the smaller number in X and the larger one in Y. Now assume there are three different numbers in X, Y and Z. X>Y? X<>Y will put the larger one in Y and the smaller one in X. Roll down the stack one level to compare this larger number with the third one. X≤Y? X<>Y will put the largest of all three in X. So the program simply is: Code: 01 LBL A Or on the 12C and others without an X>Y? test: Code: 01 X≤Y? You can easily extend this example. This is what we get: Return the largest of two numbers: Code: 01 LBL A Return the largest of three numbers: Code: 01 LBL A Return the largest of four number: Code: 01 LBL A Dieter RE: (11C) Finding biggest of 3 integers - Gamo - 10-21-2018 03:13 AM Thanks Dieter Didn't think about that before now your version is very interesting. Gamo |