Thursday, 25 October 2018

LAB ACTIVITY 5: Arithmatic Expression and Operators

a. Convert these mathematical expression into C expression

  1.  y = m*x +c
  2. (2*a) / b * 3 *c
  3. 9*p + 2*q ( r + 2 ) / 2*(s -1)
  4. ( (3*e - d) / (x - 9) ) - ( (4 - pow (c,3)) / 4*y )

b. Determine the order of solving the expressions below and calculate the value of x.
  1. x = 15
  2. x = 3
  3. x = 108
  4. x = 1

c. Given the value of num1=26. Determine the value of num2 after the execution for each of
the following statement.

  1.  24
  2.  26
  3.  24
  4. 27
d. Assume i, j and k are integer variables with i=3 and j=4. Determine the value of k for
each of the following statement. (Assume that each of the operation is non-contiguous)

  1. k = j++;
       = 4
  2. k = ++j;
       = 5
  3. k = ++i * j--;
       = 5*4
       = 20
  4. k = j++ * --i;
       = 4*2
       = 8
  5. k = j * i/j--;
       = 4* 3/4
       = 3
  6. k = 24/j++ - 16 % i;
       = 24/4 - 16 % 3
       = 6 - 1
       = 5
e.   Determine the output of the program below

  

      Output :

      1: 10
      2: 10
      3: 11
      4: 11
      5: 11
      6: 31
      7: -11
      8: 32
      9: 32
    10: 32
    11: 0
    12: 1
    13: 0


f.  Given i=2, j=5.

i)  Output: 7
ii) Output: 8
iii) Output: 9
iv) Output: 12
v)  Output: 36
    



       

No comments:

Post a Comment