C# Biggest of Three Numbers Program

Beginner
5 min read
Updated: Oct 2026
2 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

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

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 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

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

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

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.

Time and Space Complexity

ProgramTimeExtra space
If-else ladderO(1)O(1)
Nested Math.MaxO(1)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.
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.

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