Q.Write an algorithm to find the greatest among two different numbers entered by the user.
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →One comparison decides it: if num1 > num2 the first is the greatest, otherwise the second — a pure selection (if–else) algorithm.
The idea (selection). Finding the larger of two values needs no loop, just a decision: compare once and branch. Because the question guarantees the numbers are different, exactly one of num1 > num2 / num2 > num1 is true, and a plain if–else covers everything.
Algorithm
GREATEST_OF_TWO_ALGO
Step 1: INPUT num1
Step 2: INPUT num2 (num2 different from num1)
Step 3: IF num1 > num2 THEN
PRINT num1, "is the greatest"
ELSE
PRINT num2, "is the greatest"
END IF
Step 4: END
Flowchart in words: Start (oval) → Input num1, num2 (parallelogram) → Decision "num1 > num2?" (diamond) → Yes-arrow → Output num1 (parallelogram) → Stop; No-arrow → Output num2 (parallelogram) → Stop.
Python verification
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if num1 > num2:
print(num1, "is the greatest")
else: …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.