Solved

E

Posted on 2006-07-14
4
185 Views
Last Modified: 2010-04-15
Hi,

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

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

2. 9 > = 7 + 3 && 7 % 3 == 1
Answer: FALSE

3. 6 > 2 || 25 / 5 == 4
Answer:TRUE

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

5. 25 > 3 && !(6==4)
Answer: TRUE
0
Comment
Question by:dandeliondream
  • 3
4 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 125 total points
ID: 17107945
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
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 125 total points
ID: 17107957
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
 
LVL 3

Author Comment

by:dandeliondream
ID: 17108121
Thanks Infinity08.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 17108161
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

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now