Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Place parenthesis in the following expressions to explicitly show the order o

ID: 3756968 • Letter: 1

Question

1. Place parenthesis in the following expressions to explicitly show the order of evaluation. For example, b) w++ z c) 1-a>= b * 6 + 71c 2. Convert the following switch-case code to an if-else code. 1 switch n) 2 t 3 case 1: a 1*n; 5 case 2: a 2*n; break; 7 default: a 0; break; 8 3. Convert the following for loop into a while loop. 1 for ( a 100; a > 50; a-- ) 4 b-array[a]: 5 printf( "%d ", b ); 6 1 4. What will be the output of the following program: 1 int i = 43, j =-17; 2 dol 3 printf("%d", i+j); 6 while(0)

Explanation / Answer


Answeres

1)

a)   (Id == 1 ) && (!a++) (p<1) || (q*5) )

                                         |----> one more relational operator required in this position to avoid a syntax error by the compiler.

b) (w--) – (++z)

c) (1-a) >= ( (b*6) +(7/c) )

2)

if ( n>0)

       {

           if(n==1)

             a=1*n;

          else if(n==2)

             a=2*n;

      }

    else

      {

         a=0;

      }

Alternative solution which provides optimized logic as follows

if(n==1)

a=1*n;

else if (n==2)

         a=2*n;

       else

          a=0;

3)

a=100;

while(a>50)

{

      if ( a%8 != 0 )

          b -= array[a];

     printf(“%d”,b);

    

     a--;

}

4)   Output is only 26 because, the do while loop will not iterate due to the fixed constant Boolean value as false.

5) af$123.00

a

f

$

1

23

.

0

0

1

2

3

4

5

6

7

8

1st letter was displayed the printf(“%c”,’a’);

2nd letter was displayed by the printf(“%x”, 15)

       Format specified % lower case x will gives hexa decimal value of 15 , that is lower case f

3rd letter was displayed by the printf as a part of its first character

4th letter was displayed by the printf of its format specifier as %d and its defined value HI is 1

5th was displayed by the printf of its 2nd format specifier as %d and its defined value NUM is 23

6th was displayed by the printf as part of its string dot ( .)

7th was displayed the printf as of its format specifier as %c and its defined value OOPS is character constant ‘0’

8th was displayed the printf as of its format speciifer as %d and its defined value BY is numeric 0

6)

a) YYNN

Because the loop will run four times

b) 4OUO4OUO4O

c) -10 , display only one value , because the for loop terminates with semi colon, therefore for loop condition termination value was displayed by the variable i.

d) ######

    #####

    ####

    ###

7)

a)

A[0]

A[1]

A[2]

A[3]

A[4]

A[5]

A[6]

0

1

0

31

0

0

12

b)

B[0]

B[1]

B[2]

B[3]

B[4]

B[5]

B[6]

B[7]

0

0

1

0

0

1

0

1

c)

C[0][0]

C[0][1]

C[0][2]

C[1][0]

C[1][1]

C[1][2]

1

2

3

2

1

0

Specified values are mentioned as italic.

Missing array location values are filled by the compiler and those are shown in bold .

8) answer is 5

     m value is 2 and n value is 5

   so, (5*2)-5 è 10-5 è 5

9) Answer is 9

     The entire B array size is 9, because array index start from zero. B is a int data type. The size of integer is 2 bytes with respect to 16 bit compiler.

   So , the total size of array B is 18

The size of b[1] is 2 bytes with respect to 16 bit compiler, so the answer is 18 / 2 =9

In case of 32 bit compiler, the answer is also 9

   36/4 = 9

10) Answer is 1.00000

11)

12)

if ( n>0)

       {

           if(n==1)

             a=1*n;

          else if(n==2)

             a=2*n;

      }

    else

      {

         a=0;

      }

Alternative solution which provides optimized logic as follows

if(n==1)

a=1*n;

else if (n==2)

         a=2*n;

       else

          a=0;