Sunday 16 October 2011

Chapter 1: [C] Evaluate the following expressions and show their hierarchy.

(a)  g = big / 2 + big * 4 / big - big + abc / 3 ;
(abc = 2.5, big = 2, assume g to be a float)


2 / 2 + 2 * 4 / 2 - 2 + 2.5 / 3;  

1 + 2 * 4 / 2 - 2 + 2.5 / 3;

1 + 8 / 2 - 2 + 2.5 / 3;

1 + 4 - 2 + 2.5 / 3;

1 + 4 - 2 + 0; 

 5 - 2 + 0;

3+ 0

3
so
g = 3


(b)  on = ink * act / 2 + 3 / 2 * act + 2 + tig ;
(ink = 4, act = 1, tig = 3.2, assume on to be an int)

4 * 1 / 2 + 3 / 2 * 1  + 2 + 3.2

4 / 2 + 3 / 2 * 1  + 2 + 3.2

2 + 3 / 2 * 1  + 2 + 3.2

2 + 1 * 1  + 2 + 3.2 

2 + 1  + 2 + 3.2

3 + 2 + 3.2

5  + 3.2
  
8
so
on = 8


(c)  s = qui * add / 4 - 6 / 2 + 2 / 3 * 6 / god ;
(qui = 4, add = 2, god = 2, assume s to be an int)

4 * 2 / 4 - 6 / 2 + 2 / 3 * 6 / 2 

8 / 4 - 6 / 2 + 2 / 3 * 6 / 2 

2 - 6 / 2 + 2 / 3 * 6 / 2 

2  - 3 + 2 / 3 * 6 / 2 

2 - 3 + 0 * 6 / 2 

2 - 3 + 0 / 2

2 - 3 + 0 
-1 + 0

-1 

so
s= -1

 
(d)  s = 1 / 3 * a / 4 - 6 / 2 + 2 / 3 * 6 / g ;
(a = 4, g = 3, assume s to be an int)

1 / 3 * 4 / 4 - 6 / 2 + 2 / 3 * 6 / 3

0 * 4 / 4 - 6 / 2 + 2 / 3 * 6 / 3 

0 / 4 - 6 / 2 + 2 / 3 * 6 / 3 

0 - 6 / 2 + 2 / 3 * 6 / 3 

0 - 3 + 2 / 3 * 6 / 3

0 - 3 + 0 * 6 / 3

0 - 3 + 0 / 2
  
0 - 3 + 0

-3 +0

-3 

so 
s = -3



13 comments:

  1. hello ,
    (a) g = big / 2 + big * 4 / big - big + abc / 3 ;
    (abc = 2.5, big = 2, assume g to be a float)

    the correct answer is 3.83333

    ReplyDelete
    Replies
    1. your answer is not correct , because 2.5 / 3 not equal zero , 2.5 is float , so 2.5 /3 =0.833333

      Delete
    2. when done the same program in Turbo C, the s = 0,

      did you tried this??

      Delete
    3. Yes. The answer is 3.83 for (a).
      Please make the corrections.
      Thank you!

      Delete
  2. WITH THE QUESTION (d):
    0 - 3 + 0 * 6 / 3 IS DONE THIS WAY.
    0*6 FIRST THEN YOU GET -3 + 0 / 3
    WHICH WILL GIVE YOU -3+0, WHICH IS THE SAME -3.
    THANK YOU.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. He'llo friends
    The correct answer for
    (a) g = big / 2 + big * 4 / big - big + abc / 3 ;
    (abc = 2.5, big = 2, assume g to be a float)
    Is 3.833333 since float is mentioned and precision for float is upto 6 decimal place

    ReplyDelete
    Replies
    1. thanks bro.I was confused of the answer.

      Delete
    2. Bhai integer type hai not a float type

      Delete
  5. This comment has been removed by the author.

    ReplyDelete