Programming a not-so-powerful calculator

50 Views Asked by At

I have three numbers P, Q, R subject to the following conditions:-

(1) P, Q, R can be all different; or

(2) P, Q, R cannot be all equal at the same time; or

(3) Two of them are equal. That is, (P, q, r) or (p, Q, r) or (p, q, R) where small letters denote equality.

In case of (3) and the numbers are (P, Q, R), I would like to re-arrange them into the form (X, y, z). That is, the unequal one should always be in the leading position.

My programmable calculator has the switch function [S(.)] that can do S(q, P) = (P, q) but does not have the “elseif” function. How can I test, switch and re-arrange?

1

There are 1 best solutions below

1
On BEST ANSWER

You only need to check the first and second entries, and the first and third. If the second two entries are equal there's no rearrangement necessary.

input (p,q,r)
if(p==q)
   S(p,r)
if(p==r) \\ If p==r, then p !=q, so a free else-if.
   S(p,q)