C# Biggest of Three Numbers Program

Beginner
5 min read
Updated: Sep 2026
3 programs
Live preview

What Is the Biggest of Three Numbers?

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
abcBiggest
1422722
-1-4-2-1
5535 (tie)
9999

How to Find the Biggest in C#

Two solid options — show the ladder in interviews, use Math.Max in apps.

  1. Read three numbers a, b, c.
  2. Compare with >= (handles ties).
  3. Return the winner — or nest Math.Max.
  4. Test negatives and equal values.
MethodIdeaBest for
If-else laddera >= b && a >= c, then check b, else cInterviews (shows logic)
Nested Math.MaxMath.Max(Math.Max(a, b), c)Short application code
Custom Max2Helper that returns the larger of two, then nestTeaching without library calls

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

Cheat sheet

GoalPattern
a winsa >= b && a >= c
b winsb >= a && b >= c
Library shortcutMath.Max(Math.Max(a, b), c)
TiesPrefer >= so equal maxima still return

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

Worked Walkthrough — 14, 22, 7

Apply the if-else ladder with >=.

CheckResult
14 >= 22 && 14 >= 7false (a is not biggest)
22 >= 14 && 22 >= 7true → return 22

No need to test c once b wins. Same result as Math.Max(Math.Max(14, 22), 7).

C# Programs

Three programs: if-else ladder, nested Math.Max, and a custom Max2 helper. Use View Output for sample results.

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));
    }
}

How It Works

1. Test a. If a is at least as large as b and c, return a.

2. Test b. Otherwise, if b beats both, return b.

3. Else c. The remaining case is that c is the biggest (or tied and reached last).

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));
    }
}

How It Works

1. Pairwise max. Math.Max(a, b) picks the larger of the first two.

2. Fold in c. Math.Max(that, c) finishes the three-way maximum.

3. Same result. Equivalent to the if-else ladder — shorter once the logic is clear.

Example 3 — Custom Max2 Helper

Teach the idea without calling the library — nest your own two-argument max.

C#
using System;

class Program
{
    static int Max2(int x, int y)
    {
        return x >= y ? x : y;
    }

    static int Biggest(int a, int b, int c)
    {
        return Max2(Max2(a, b), c);
    }

    static void Main()
    {
        Console.WriteLine(Biggest(14, 22, 7));   // 22
        Console.WriteLine(Biggest(-1, -4, -2));  // -1
        Console.WriteLine(Biggest(5, 5, 3));     // 5
    }
}

How It Works

1. Max of two. Max2 returns the larger of a pair using >=.

2. Nest for three. Max2(Max2(a, b), c) mirrors nested Math.Max.

3. Cover edge cases. Negatives and ties behave correctly — assert them in interviews.

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.

Sort?

Unnecessary

Sorting three values works but is overkill — prefer comparisons.

Interview

Ladder first

Write if-else, then mention Math.Max as a shortcut.

Many values

Use a loop

For N > 3, keep a running maximum instead of deeper nesting.

Time and Space Complexity

ProgramTimeExtra space
If-else ladderO(1)O(1)
Nested Math.MaxO(1)O(1)
Running max over N valuesO(N)O(1)

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.
Any of them is a valid answer — they all share the same maximum.
Yes. Among negatives, the largest is the least negative (for example max(-1, -4, -2) is -1).
For exactly three numbers, time is O(1) and extra space is O(1).
Use a loop with a running maximum, or fold Math.Max across an array.
Yes. It is equivalent to Math.Max(Math.Max(a, b), c) and still O(1).
You can, but sorting is unnecessary overhead for a fixed count of three. Prefer comparisons or Math.Max.
The same comparison logic works for double. Be careful with NaN if you accept user floats.

Did you know?

With only three values you need a handful of comparisons, so the check is O(1) time and O(1) extra space.

Next: Binary to Decimal

Convert a binary string into its decimal value.

Binary to decimal tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful