Question

Evaluate each of the following C++ expressions. (a) i1 + (i2 * i3) (b) i1 *...

Evaluate each of the following C++ expressions. (a) i1 + (i2 * i3) (b) i1 * (i2 + i3) (c) i1 / (i2 + i3) (d) i1 / i2 + i3 (e) 3 + 4 + 5 / 3 (f) (3 + 4 + 5) / 3 (g) d1 + (d2 * d3) (h) d1 + d2 * d3 (i) d1 / d2 - d3 (j) d1 / (d2 - d3) (k) d1 + d2 + d3 / 3 (l) (d1 + d2 + d3) / 3 (m) d1 + d2 + (d3 / 3) (n) 3 * (d1 + d2) * (d1 - d3)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

For the evaluation of expressions you didn't provide the values for variables like i1, i2, i3 etc. So I am assuming the values and evaluating expressions using them. Evaluation of these expressions is based on the precedence and associativity of the operators.

Let

int i1 = 2, i2 = 5, i3 = -3;
double d1 = 2.0, d2 = 5.0, d3 = -0.5;

Now come to the question,

(a) i1 + (i2 * i3) = -13

2 + (5 * -3) = 2 - 15 = -13

(b) i1 * (i2 + i3) = 4

2 * (5 + -3) = 2 * 2 = 4

(c) i1 / (i2 + i3) = 1

2 / (5 + -3) = 2 / 2 = 1

(d) i1 / i2 + i3 = -3

2 / 5 + -3 = 0 + -3 = -3 (fraction part .4 in 2 / 5 (that is 2 / 5 = 0.4) will be truncated because operation is performed on int datatype so 2 / 5 yields 0)

(e) 3 + 4 + 5 / 3 = 8

3 + 4 + 1 = 8 (fraction part will be truncated because operation is performed on int datatype. 5 / 3 yields 1)

(f) (3 + 4 + 5) / 3 = 4

(3 + 4 + 5) / 3 = 12 / 3 = 4

(g) d1 + (d2 * d3) = -0.5

2.0 + (5.0 * -0.5) = 2.0 - 2.5 = -0.5

(h) d1 + d2 * d3 = -0.5

2.0 + 5.0 * -0.5 = 2.0 - 2.5 = -0.5

(i) d1 / d2 - d3 = 0.9

2.0 / 5.0 - (-0.5) = 0.4 + 0.5 = 0.9

(j) d1 / (d2 - d3) = 0.363636

2.0 / (5.0 - -0.5) = 2.0 / 5.5 = 0.363636

(k) d1 + d2 + d3 / 3 = 6.83333

2.0 + 5.0 + -0.5 / 3 = 7.0 - 0.166667 = 6.83333

(l) (d1 + d2 + d3) / 3 = 2.16667

(2.0 + 5.0 + -0.5) / 3 = 2.16667

(m) d1 + d2 + (d3 / 3) = 6.83333

2.0 + 5.0 + (-0.5 / 3) = 7.0 - 0.166667 = 6.83333

(n) 3 * (d1 + d2) * (d1 - d3) = 52.5

3 * (2.0 + 5.0) * (2.0 - -0.5) = 3 * 7.0 * 2.5 = 52.5

Please give thumbsup, if you like it. Thanks.

Add a comment
Know the answer?
Add Answer to:
Evaluate each of the following C++ expressions. (a) i1 + (i2 * i3) (b) i1 *...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT