Introduction to Problem Solving · Class 11 · CBSE · Science Computer Science
Consider the following pseudocode for finding the largest of three numbers: read a, b, c; largest = a; if b > largest then largest = b; if c > larges…
Practice question from Introduction to Problem Solving (Class 11 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.
hard · MCQ · Q-2C91EC
Consider the following pseudocode for finding the largest of three numbers: read a, b, c; largest = a; if b > largest then largest = b; if c > largest then largest = c; display largest. If the second if statement is replaced by an else-if connected to the first if statement, what problem can occur?
- A.The value of a can never be used as the initial largest value
- B.The algorithm will always display the smallest number
- C.The comparison with c may be skipped even when c is the largest numberCorrect answer
- D.The algorithm will become an infinite loop
Solution
The comparison with c must be performed independently after updating largest with b. Using else-if can skip that comparison when b is greater than a, even if c is greater than both.
More from Introduction to Problem Solving
- Which sequence best represents the main stages of solving a programming problem?
- Consider the following pseudocode: set n to 5; while n > 0, display n. Which essential property of an algorithm is not satisfied?
- Explain how problem decomposition helps in solving a programming problem. Use the task of preparing a student's result as an example and me…
- Which statement correctly describes an algorithm?
Practise more Computer Science
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed