Consider the following code segment: if (Y < 0) {X = -X; Y = -Y;} Z = 0; while…

KVS TGT/PGT 2017Kendriya Vidyalaya Sangathan 2017

Consider the following code segment: if (Y < 0) {X = -X; Y = -Y;} Z = 0; while (Y > 0) {Z = Z + X; Y = Y - 1;} Assume that X, Y and Z are integer variables , and that X and Y have been initialized . Which of the following best describes what this code does?

  1. A.

    Sets Z to be the product X * Y

  2. B.

    Sets Z to be the sum X + Y

  3. C.

    Sets Z to be the absolute value of X

  4. D.

    Sets Z to be the value of Y

Attempted by 333 students.

Sign up free to check your answer

Sign up free

Explore the full course: Bpsc

Loading lesson…