Pascal numeric operations with TRUNC: Given X := 2.57; then X := (X + 0.06) * 10; I := TRUNC(X); X := I; X := X / 10.0; what is the final value of X?

Difficulty: Medium

Correct Answer: 2.6

Explanation:


Introduction / Context:
This problem exercises understanding of floating operations, truncation to integer, and reassignment in Pascal. TRUNC removes the fractional part (toward zero), which affects subsequent computations when we convert back to real and rescale.


Given Data / Assumptions:

  • Initial X = 2.57 (real).
  • Operations: add 0.06, scale by 10, TRUNC to integer I, assign back to X, then divide by 10.0.
  • TRUNC(x) discards the fractional part, e.g., TRUNC(26.3) = 26.


Concept / Approach:
Follow the sequence carefully; TRUNC changes 26.3 to 26, and subsequent division by 10.0 yields 2.6, not the pre-TRUNC value. This is a classic rounding vs truncation illustration.


Step-by-Step Solution:

Start: X = 2.57.Compute (X + 0.06) * 10 = (2.57 + 0.06) * 10 = 2.63 * 10 = 26.3.I := TRUNC(26.3) = 26.X := I → X = 26.X := X / 10.0 → 26 / 10.0 = 2.6.


Verification / Alternative check:
If instead of TRUNC we had used ROUND, the result could become 2.6 or 2.63 depending on rounding behavior; here TRUNC explicitly removes the fractional part, confirming 2.6.


Why Other Options Are Wrong:

2 or 26.3 ignore the subsequent steps.2.63 would be true before TRUNC and reassignment; it is not the final value.2.57 is the initial value only.


Common Pitfalls:

Confusing TRUNC with ROUND; forgetting reassignment X := I before dividing by 10.0.


Final Answer:

2.6

More Questions from Microprocessors

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion