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#
Two solid options — show the ladder in interviews, use Math.Max in apps.
Read three numbers a, b, c.
Compare with >= (handles ties).
Return the winner — or nest Math.Max.
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 Math.Max
Math.Max(Math.Max(a, b), c)
Short application code
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
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 use nested Math.Max for shorter application code.
Example 1 — If-Else Ladder
Interview default: compare with >= and return the winner.
C#
using System;
class Program
{
static 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;
}
}
static void Main()
{
int a = 14, b = 22, c = 7;
Console.WriteLine("The biggest number is: " + Biggest(a, b, c));
}
}
Output
The biggest number is: 22
How it works: test whether a is at least as large as both values, then test b. If neither wins, return c.
Example 2 — Nested Math.Max
Math.Max takes two arguments, so nest a call for three values.
C#
using System;
class Program
{
static int Biggest(int a, int b, int c)
{
return Math.Max(Math.Max(a, b), c);
}
static void Main()
{
Console.Write("Enter three integers (a b c): ");
string[] parts = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 3
|| !int.TryParse(parts[0], out int a)
|| !int.TryParse(parts[1], out int b)
|| !int.TryParse(parts[2], out int c))
{
Console.WriteLine("Please enter three integers.");
return;
}
Console.WriteLine("The biggest number is: " + Biggest(a, b, c));
}
}
Output (when user enters 14 22 7)
Enter three integers (a b c): 14 22 7
The biggest number is: 22
How it works: the inner Math.Max(a, b) finds the larger of the first two values. The outer call compares that result with c.
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 Math.Max
O(1)
O(1)
Remember
Key Takeaways
Goal: return the largest among a, b, and c.
Use >=: ties still return a valid maximum.
Shortcut:Math.Max(Math.Max(a, b), c).
Test set: 14,22,7 → 22; -1,-4,-2 → -1; 5,5,3 → 5.
One line: compare with a few >= checks (or nest Math.Max) and return the largest.
Frequently Asked Questions
Compare a, b, and c with if-else (using >=), or nest Math.Max: Math.Max(Math.Max(a, b), c). Both return the largest value.
>= handles ties cleanly. If two values share the maximum, one of them is still returned correctly.
Yes. Math.Max takes two arguments, so nest it for three: Math.Max(Math.Max(a, 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 Math.Max methods take O(1) time and O(1) extra space.