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

What value is assigned to A (type int) by the statement below, assuming A is 5 A

ID: 3596225 • Letter: W

Question

What value is assigned to A (type int) by the statement below, assuming A is 5

A= A/ 20;

0

0.25

1

0.5

What is the value of X after execution of the following code?

       int X = 10;

       for (int ctr = 0; ctr < 2; ctr++)

            {

              X= X – 1;

              X= X + 1;

            }

13

8

10

9

What is the value of t after the following code is executed?

       int t = 0, c = 0, x = 3;

       while (c < 4)

       {

                 t = t + x;

                 x = x * 2;

                 c = c + 1;

        }

21

48

45

12

What is the value of y after the following code segment?

      int x = 5, y = 3;

      do

          {

                 x = x * 2;

                 y = y + 2;

          } while (y < 7);

Error

7

5

20

What is wrong with the following code?

int sum, number;

int counter = 0;

while (counter < 10)

{

cin >> number;

sum = sum + number;

counter = counter + 1;

}

no output

No update of the loop control variable

Nothing wrong

sum must be initialized to 0

0

0.25

1

0.5

Explanation / Answer

1. 0 :The assigned value of A is 0.

Because 5/20 is equal to 0.25. But A is defined by int value so it won't read fractional value. So A value is 0.

2. 10: The value of X is 10.

Intial value of X is 10. In loop the value of is will be

X=X-1 #9

X=X+1 #10

Loop continues value of X is always be 10.

3. 45: the value of t is 45

For loop you will get below values

C t X

0 3 6

1 9 12

2 21 24

3 45 48

4. 7: Value of y is 7

As per the loop intial value of y is 3. After the first iteration value of y is 5 which is less than 7. SO loop contuines now the value of y is 7. And based on condition loop will terminate.

5. sum must be initialized to 0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote