Given three numbers a, b, and c, the biggest is the one that is greater than or equal to both of the others.
Remember
biggest(a, b, c) = the maximum among a, b, and c
Example: a = 14, b = 7, c = 22
22 >= 14 and 22 >= 7 → biggest = 22
Ties: if two share the max, either is a valid answer
a
b
c
Biggest
14
7
22
22
5
5
3
5
-1
-4
-2
-1
9
9
9
9
Approach
How to Find the Biggest of Three Numbers in C++
Compare pairwise — a few comparisons are enough for three fixed values.
If a >= b and a >= c, return a.
Else if b >= a and b >= c, return b.
Otherwise return c.
Method
Idea
Time
Best for
If-else ladder
Explicit comparisons
O(1)
Interviews, clarity
Nested std::max
max(max(a,b), c)
O(1)
Idiomatic C++
Custom max2
Pairwise helper, then nest
O(1)
Teaching pairwise max
Pseudocode
Pseudocode
function Biggest(a, b, c):
if a >= b and a >= c:
return a
else if b >= a and b >= c:
return b
else:
return c
Reference
Cheat Sheet
Keep these facts handy while writing the program.
Topic
Detail
Goal
Return the maximum of three values
Ties
Use >= so equal max values still work
Library
std::max from <algorithm>
Negatives
Comparisons work the same way
Complexity
O(1) time and space
Try it
Live Preview
Enter three numbers to see which one is biggest and why.
Any integers (including negatives). Tap a chip or type values.
Result
a = 14, b = 7, c = 22
22 >= 14 and 22 >= 7
Biggest = 22
Trace
Worked Walkthrough — 14, 7, 22
Test each branch of the if-else ladder.
Calculation
a = 14, b = 7, c = 22
Is a biggest?
14 >= 7 ✓ but 14 >= 22 ✗
Is b biggest?
7 >= 14 ✗
Otherwise c is biggest
Biggest = 22
Code
C++ Programs
Start with an if-else ladder. Then nest std::max, and finish with a custom pairwise helper.
Example 1 — If-Else Approach
Check a, then b, otherwise return c — using >= for ties.
C++
#include <iostream>
int findBiggest(int num1, int num2, int num3) {
if (num1 >= num2 && num1 >= num3) {
return num1;
} else if (num2 >= num1 && num2 >= num3) {
return num2;
}
return num3;
}
int main() {
int number1 = 14;
int number2 = 7;
int number3 = 22;
int result = findBiggest(number1, number2, number3);
std::cout << "The biggest number is: " << result << "\n";
return 0;
}
Output
The biggest number is: 22
How It Works
If num1 is >= both others, return it.
Else if num2 is >= both others, return it.
Otherwise num3 must be the biggest.
>= keeps ties correct (equal max values still match).
For 14, 7, 22 the third branch returns 22.
Example 2 — Nested std::max
std::max takes two args, so nest a call for three values.
C++
#include <iostream>
#include <algorithm>
int findBiggestWithMax(int a, int b, int c) {
return std::max(std::max(a, b), c);
}
int main() {
int a = 14;
int b = 7;
int c = 22;
std::cout << "The biggest number is: " << findBiggestWithMax(a, b, c) << "\n";
return 0;
}
Output
The biggest number is: 22
How It Works
Include <algorithm> for std::max.
std::max(a, b) returns the larger of the first pair.
Nest with c to cover all three values.
Same answer as the if-else version — less code.
Great after you have already explained the comparison logic.
Example 3 — Custom max2 Helper
First take the larger of b and c, then compare with a.
C++
#include <iostream>
int max2(int a, int b) {
return (a >= b) ? a : b;
}
int findBiggestNested(int a, int b, int c) {
return max2(a, max2(b, c));
}
int main() {
std::cout << findBiggestNested(5, 5, 3) << "\n";
std::cout << findBiggestNested(-1, -4, -2) << "\n";
return 0;
}
Output
5
-1
How It Works
max2 returns the larger of two values (ties keep the first).
max2(b, c) reduces two values to one candidate.
max2(a, …) finishes the three-way max.
Tie case 5, 5, 3 returns 5.
All-negative case -1, -4, -2 returns -1.
Edge Cases & Pitfalls
Check these before calling the solution done.
Ties
Use >= not only >
Equal maximum values still need a correct return. Prefer >=.
Negatives
Largest can be negative
Among -1, -4, -2 the biggest is -1 — not the closest to zero by absolute value.
All equal
Any value is fine
If a = b = c, every branch that uses >= returns the shared maximum.
N values
Extend with a loop
For many numbers, use a running maximum (or max of an array) instead of nested ifs.
Analysis
Time and Space Complexity
Program
Time
Extra space
If-else / std::max / max2
O(1)
O(1)
N numbers (loop)
O(N)
O(1)
Three fixed comparisons never grow with input size — constant work.