• C

# E

Hi,

Why are the following conditions correct? Could someone please explain to me.

1. 16 % 3 < 22 ==  6 / 3 >= 2

2. 9 > = 7 + 3 && 7 % 3 == 1

3. 6 > 2 || 25 / 5 == 4

4. 7 <= 9 || 6 > 5 && 7 == 2

5. 25 > 3 && !(6==4)
LVL 3
###### Who is Participating?

Commented:
I suggest you add brackets using the operator precedence table :

http://www.difranco.net/cop2220/op-prec.htm

so you get a clearer view on what goes with what.

Then just calculate step by step.

I'll give you one example for the first question - the rest I leave up to you :

16 % 3 < 22 ==  6 / 3 >= 2

is the same as :

(((16 % 3) < 22) ==  ((6 / 3) >= 2))

So :

((1 < 22) ==  (2 >= 2))

Or :

(1 ==  1)

Or :

1

which is TRUE.
0

Commented:
Note that this step :

(1 ==  1)

is very dangerous in actual code, because there's no guarantee that both sides will be 1 (the only guarantee is that they will be values different from 0).

So, on some platforms, this might be :

(1 == 2)

which would be FALSE.

For these exercises you can assume that TRUE is always 1 though !
0

Author Commented:
Thanks Infinity08.
0

Commented:
If you have trouble figuring out the other 4, feel free to post your solutions here, and I'll take a look at them.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.