Given three numbers a, b, and c, find the largest value — the one that is greater than or equal to both of the others. Ties are allowed: any tied maximum is a valid answer.
Remember
biggest = max(a, b, c)
If a ≥ b and a ≥ c → a
Else if b ≥ a and b ≥ c → b
Else → c
Example: 14, 22, 7 → biggest is 22
a
b
c
Biggest
14
22
7
22
-1
-4
-2
-1
5
5
3
5 (tie)
9
9
9
9
Approach
How to Find the Biggest in C
Four clear steps — show the ladder in interviews.
Read three numbers a, b, c.
Compare with >= (handles ties).
Return the winner — or use a nested ternary.
Test negatives and equal values.
Method
Idea
Best for
If-else ladder
a >= b && a >= c, then check b, else c
Interviews (shows logic)
Nested ternary
a >= b ? (a >= c ? a : c) : (b >= c ? b : c)
Short application code
Running max
Start with a, update if b or c is larger
Scales to N values
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
Compare
Use >= so ties still return a max
Ladder
Check a, then b, else c
Ties
Any equal largest value is correct
Negatives
max(-1, -4, -2) = -1
Classic check
14, 22, 7 → 22
Try it
Live Preview
Enter three numbers to see each comparison and the biggest value.
Integers or decimals. Ties return one of the equal largest values.
Result
a = 14, b = 22, c = 7
a >= b && a >= c? false
b >= a && b >= c? true
Biggest = 22
Trace
Worked Walkthrough — 14, 22, 7
Apply the if-else comparisons from left to right.
Calculation
a check: 14 >= 22 && 14 >= 7 → false
b check: 22 >= 14 && 22 >= 7 → true
Result: b is the biggest value → 22
Code
C Programs
Start with the if-else solution, then a nested ternary, and finish with user input.
Example 1 — If-Else Ladder
Interview default: compare with >= and return the winner.
C
#include <stdio.h>
int biggest(int a, int b, int c)
{
if (a >= b && a >= c)
{
return a;
}
else if (b >= a && b >= c)
{
return b;
}
else
{
return c;
}
}
int main(void)
{
int a = 14, b = 22, c = 7;
printf("The biggest number is: %d\n", biggest(a, b, c));
return 0;
}
Output
The biggest number is: 22
How It Works
Test whether a is at least as large as both b and c.
If not, test whether b is at least as large as both others.
Otherwise return c.
For 14, 22, 7, the a check fails and the b check succeeds.
Result is 22.
Example 2 — Nested Ternary
Same logic in one expression — useful once the ladder is clear.
C
#include <stdio.h>
int biggest(int a, int b, int c)
{
return a >= b ? (a >= c ? a : c) : (b >= c ? b : c);
}
int main(void)
{
int a = 14, b = 22, c = 7;
printf("The biggest number is: %d\n", biggest(a, b, c));
return 0;
}
Output
The biggest number is: 22
How It Works
Outer choice: is a >= b?
If yes, pick the larger of a and c.
If no, pick the larger of b and c.
Here 14 >= 22 is false, so compare 22 and 7.
Result is 22 — same as Example 1.
Example 3 — User Input
Read three integers with scanf, then reuse the same helper.
C
#include <stdio.h>
int biggest(int a, int b, int c)
{
if (a >= b && a >= c)
{
return a;
}
else if (b >= a && b >= c)
{
return b;
}
else
{
return c;
}
}
int main(void)
{
int a, b, c;
printf("Enter three integers (a b c): ");
if (scanf("%d %d %d", &a, &b, &c) != 3)
{
printf("Please enter three integers.\n");
return 1;
}
printf("The biggest number is: %d\n", biggest(a, b, c));
return 0;
}
Output (when user enters 14 22 7)
Enter three integers (a b c): 14 22 7
The biggest number is: 22
How It Works
scanf reads three integers into a, b, and c.
If fewer than three values are read, print an error and exit.
Call the same biggest helper from Example 1.
Input and comparison stay separate — easy to test.
Sample input 14 22 7 prints 22.
Edge Cases & Pitfalls
Check these before calling the solution done.
> vs >=
Prefer >=
Strict > can skip equal largest values depending on branch order.
Ties
Any max is fine
If two or three share the maximum, returning one of them is correct.
Negatives
Least negative wins
max(-1, -4, -2) is -1, not the largest magnitude.
Many values
Use a loop
For N > 3, keep a running maximum instead of deeper nesting.
Analysis
Time and Space Complexity
Program
Time
Extra space
If-else ladder
O(1)
O(1)
Nested ternary
O(1)
O(1)
User input + helper
O(1)
O(1)
Three comparisons (at most) — constant work for a fixed count of inputs.
Remember
Key Takeaways
Goal: return the largest among a, b, and c.
Use >=: ties still return a valid maximum.
Shortcut: nested ternary or a short if-else ladder.
Test set: 14,22,7 → 22; -1,-4,-2 → -1; 5,5,3 → 5.
One line: compare with a few >= checks and return the largest.
Frequently Asked Questions
Compare a, b, and c with if-else using >=, or nest ternary operators. Both return the largest value.
>= handles ties cleanly. If two values share the maximum, one of them is still returned correctly.
Yes. Nested ternaries work: a >= b ? (a >= c ? a : c) : (b >= c ? b : c). In interviews, show the if-else version first.
Yes. Among negatives, the largest is the least negative (for example max(-1, -4, -2) is -1).
For exactly three numbers, both the if-else and ternary methods take O(1) time and O(1) extra space.