arrow
arrow
arrow
Start Read n1, n2 If n1 > n2 then Print n1 Else Print n2 End if Stop What will be the output if we change the condition to n1<n2
Question

Start
Read n1, n2
If n1 > n2 then
Print n1
Else
Print n2
End if
Stop
What will be the output if we change the condition to n1<n2?

A.

n1 will be displayed

B.

Largest of the two numbers will be displayed

C.

Smallest of the two numbers will be displayed

D.

n2 will be displayed

Correct option is C

In the original code, the condition is n1 > n2, so if n1 is greater, it gets printed; otherwise, n2 is printed — effectively printing the larger value.

When the condition is changed to n1 < n2, it reverses the logic — now if n1 is less than n2, then n1 will be printed; otherwise, n2 will be printed. This results in always printing the smaller of the two numbers.

Important Key Points:

  1. Changing the condition from > to < switches the focus from maximum to minimum.
  2. Both branches (if and else) print one of the two inputs, ensuring one output in all cases.
  3. Logical comparison operators like < or > dictate which value is chosen based on relative magnitude.

Knowledge Booster:

  • n1 will be displayed: Not always true — it depends on the comparison. If n2 < n1, then n2 will be printed.
  • Largest of the two numbers will be displayed: This is true only when using n1 > n2, not when using n1 < n2.
  • n2 will be displayed: Again, only true if n1 is not less than n2; not guaranteed.

Free Tests

Free
Must Attempt

UP SI 2025 Full Mock Test : 01

languageIcon English
  • pdpQsnIcon160 Questions
  • pdpsheetsIcon400 Marks
  • timerIcon120 Mins
languageIcon English
Free
Must Attempt

UP Police Constable Full Mock Test 01

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon300 Marks
  • timerIcon120 Mins
languageIcon English
Free
Must Attempt

Government Policies and Scheme

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon5 Mins
languageIcon English
test-prime-package

Access ‘UPSSSC’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
354k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow