T
T
TOcvb2020-07-19 17:36:59
C++ / C#
TOcvb, 2020-07-19 17:36:59

How to compare 3 numbers using if?

5f1457ffac8c8735895275.png
I can not find a solution to the problem because at the time of comparing the numbers, the compiler starts to behave inappropriately. So the problem is not in the compiler. After sitting and poking the buttons with a stick and a stone, I realized that everything works if the last number is 0. As soon as this equality changes, it shows the "minimum" - positive, and
"the maximum - negative.
In general, here is one of the examples that worked for me with zero, but with other integers everything goes to hell.
https://onlinegdb.com/Bya0vCZlv

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sokolov, 2020-07-19
@TOcvb

spoiler
if (a > b) {
        larg = a;
        small = b;
        
        if (c > a) larg = c;
        else if (b > c) small = c;
    } else {
        larg = b;
        small = a;
        
        if (c > b) larg = c;
        else if (a > c) small = c;
    }

R
Ronald McDonald, 2020-07-19
@Zoominger

q > e > w
Sishka does not know how, share the condition.

W
wisgest, 2020-07-19
@wisgest

a<b<c
works, but not like in mathematics, but like this:
(a<b)<c
- the truth value of the expression a<b(0 or 1) is compared with c.
To write a chain of (in)equalities, you must use the compound condition "and" ( &&):
(a<b)&&(b<c)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question