Find Larger Number
Given two integers, return the larger of the two. If they are equal, return either one (they are the same). This is a simple comparison problem that teaches conditional logic.
For example, the larger of 5 and 3 is 5. The larger of -2 and 7 is 7. The larger of 10 and 10 is 10 (either is correct).
Finding the larger of two numbers is the simplest form of comparison-based decision making. It teaches the if-else conditional structure and the greater-than operator. This pattern is the building block for more complex operations like finding the maximum of an array, sorting algorithms, and tournament-style elimination.
The solution compares a and b using if-else logic. If a is greater than b, return a. Otherwise, return b. This handles all cases including equal numbers.
Edge cases include equal numbers (return either), negative numbers (comparison works naturally), and very large numbers where the comparison still works correctly.
Example Input & Output
Both values are equal, so the result is 7.
12 is larger than 3.
9 is larger than 4.
Algorithm Flow

Solution Approach
Compare the two numbers using a conditional statement and return whichever is larger.
If a is greater than b, return a as the larger value. Otherwise, return b. This works correctly when a equals b — the else branch returns b, which has the same value as a. The greater-than comparison operator works correctly for positive numbers, negative numbers, and zero without any special handling.
Time complexity is O(1) since only a single comparison is performed. Space complexity is O(1).
Best Answers
program find_larger_number
dictionary
a, b: integer
algorithm
input(a, b)
if a >= b then
output(a)
else
output(b)
endif
endprogramComments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
