Given JCOKE = 98 and LPEPSI = 42, evaluate the Fortran-style arithmetic IF: IF (JCOKE - 3 * LPEPSI) 5, 6, 7 with labels 5: JCOKE = JCOKE + 5, 6: JCOKE = JCOKE + 8, 7: JCOKE = JCOKE + 11. What is the final value of JCOKE?

Difficulty: Medium

Correct Answer: 103

Explanation:


Introduction:
This problem checks knowledge of the classic Fortran arithmetic IF statement and evaluates control flow based on the sign of an expression. Understanding how labels are chosen for negative, zero, or positive results is the key concept.


Given Data / Assumptions:

  • JCOKE = 98
  • LPEPSI = 42
  • Statement: IF (JCOKE - 3 * LPEPSI) 5, 6, 7
  • Label actions: 5: JCOKE = JCOKE + 5; 6: JCOKE = JCOKE + 8; 7: JCOKE = JCOKE + 11


Concept / Approach:

In Fortran's arithmetic IF, the control transfers to the first label if the expression is negative, to the second label if the expression is zero, and to the third label if the expression is positive. So we compute the expression and then select the corresponding label to update JCOKE.


Step-by-Step Solution:

Step 1: Compute the expression value: JCOKE - 3 * LPEPSI = 98 - 3 * 42.Step 2: Evaluate the multiplication first: 3 * 42 = 126.Step 3: Subtract: 98 - 126 = -28.Step 4: Since the result -28 is negative, branch to label 5.Step 5: Apply label 5: JCOKE = JCOKE + 5 = 98 + 5 = 103.


Verification / Alternative check:

Check other branches to ensure they do not apply: zero would go to label 6, positive to label 7. Because -28 is negative, label 5 is uniquely correct.


Why Other Options Are Wrong:

106 – corresponds to label 6 (zero case), not applicable. 109 – corresponds to label 7 (positive case), not applicable. 'none of the above' – incorrect because 103 matches label 5.


Common Pitfalls:

Misremembering arithmetic IF semantics; performing operations in the wrong order; treating arithmetic IF as logical IF.


Final Answer:

103

More Questions from Microprocessors

Discussion & Comments

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