LAB 5 - BIC10204

 QUESTION a:

a. Convert this mathematical expression into C expression:


ANSWER FOR QUESTION a:

    i)    y = (m*x) + c

    

    ii)   ((2*a)/b)*(3*c)

    

    iii)  ((9*p)+(2*q*(r+2)))/(2*(s-1))

    

    iv)   (((3*e)-d)/(x-9))-(4-(3*pow(c,2))/(4*y))


QUESTION b:

b. Determine the order of solving the expressions below and calculate the value of x.


ANSWER FOR QUESTION b:

    i)    x = ((6/2)*3)+7-1

          x = 3*3+6

          x = 15

          

    ii)   x = (2%2)+(2*2)-(2/2)

          x = 0+4-1

          x = 3

          

    iii)  x = ((3/3)*9+3)*3*3

          x = 12*9

          x = 108

          

    iv)   x = (((4*3)/(12/2))+3)–(4*1)

          x = (2+3)-4

          x = 1

QUESTION c:

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


ANSWER FOR QUESTION c:

         num1=26, num2

    i)   num2 = num1++ - 2;

         num2 = 26 - 2;

         num2 = 24;

         

    ii)  num2 = num1;

         num2 = 27;

         num2 = 27;

         

    iii) num2 = ++num1 - 3;

         num2 = 28 - 3;

         num2 = 25;

         

    iv)  num2 = num1 + 1;

         num2 = 28 + 1;

         num2 = 29;


QUESTION d:

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).


ANSWER FOR QUESTION d:


         i=3, j=4, k

    i)   k = j++;

         k = 4;

         

    ii)  k = ++j;

         k = 5;

         

    iii) k = ++i * j--;

         k = 16;

         

    iv)  k = j++ * --i;

         k = 8;

         

    v)   k = j * i/j--;

         k = 3;

         

    vi)  k = 24/j++ - 16 % i;

         k = 5;

QUESTION e:

e. Determine the output of the program below.


ANSWER FOR QUESTION e:

            1  = 10

        2  = 10

        3  = 11

        4  = 12

        5  = 12

        6  = 31

        7  = -11

        8  = 33

        9  = 33

        10 = 33

        11 = 0

        12 = 1

        13 = 0

QUESTION f:

f. Create expression for each of the following output. You may use unary or binary operators or combination of both. (Assume every statement is noncontiguous)

Given i = 2, j = 5. 

Examples:

Output : 3 Answer : ++i;

Output : 6 Answer : i++ + --j;

i. 7

ii. 8

iii. 9

iv. 12

v. 36

ANSWER FOR QUESTION f:

         i)   printf("\n%d", i+j);

    

    ii)  printf("\n%d", (++i)+j);

    

    iii) printf("\n%d", (++i)+(++j));

    

    iv)  printf("\n%d", i+(2*j));

    

    v)   printf("\n%d", (3*i)+(6*j));

                                                                                                     Written by Arif (AI210125)😁.

Comments

Popular reaches : 3

LAB 6 - BIC10204

Lab Task 1 - BIC10503

LAB 4 - BIC10204

Lab Task 6 - BIC10503

Lab Task 3 - BIC10503

LAB 8 - BIC10204