CompTIA Tech+ (FC0-U71)Software Development ConceptsMedium

An algorithm is represented by the following pseudocode: FUNCTION CalculateResult(num1, num2): IF num1 > num2 THEN RETURN num1 * 2 ELSE IF num1 < num2 THEN RETURN num2 + 5 ELSE RETURN num1 + num2 END FUNCTION What is the output of CalculateResult(10, 10)?

  1. A15
  2. B20
  3. C100
  4. D25
Show answer & explanation

Correct answer: B. 20

When CalculateResult(10, 10) is called, num1 is 10 and num2 is 10. The first condition (num1 > num2) is false (10 > 10 is false). The second condition (num1 < num2) is also false (10 < 10 is false). Therefore, the ELSE block is executed, which returns num1 + num2. So, 10 + 10 = 20.

Why the other options are wrong

  • A. Incorrect. This would be true if num1 were, for example, 5 and num2 were 10 (10 + 5 = 15).
  • C. Incorrect. This would be true if num1 * num2 were returned, but only if the first condition was met for a different operation (e.g., num1 * 2).
  • D. Incorrect. This would be true if num1 were, for example, 10 and num2 were 5 (5 * 2 = 10, plus some other logic).

Branching (If-Else Statements)

A control flow construct that allows a program to execute different blocks of code based on whether a specified condition evaluates to true or false.

  • Executes code conditionally.
  • Uses IF, ELSE IF, and ELSE keywords.
  • Only one block of code is executed per branching structure.

Memory trick: If this, then that; else, the other.

More Software Development Concepts questions