C Biggest of Three Numbers Program

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

Four clear steps — show the ladder in interviews.

  1. Read three numbers a, b, c.
  2. Compare with >= (handles ties).
  3. Return the winner — or use a nested ternary.
  4. Test negatives and equal values.
MethodIdeaBest for
If-else laddera >= b && a >= c, then check b, else cInterviews (shows logic)
Nested ternarya >= b ? (a >= c ? a : c) : (b >= c ? b : c)Short application code
Running maxStart with a, update if b or c is largerScales 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

Cheat Sheet

Keep these facts handy while writing the program.

TopicDetail
CompareUse >= so ties still return a max
LadderCheck a, then b, else c
TiesAny equal largest value is correct
Negativesmax(-1, -4, -2) = -1
Classic check14, 22, 7 → 22

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

How It Works

  1. Test whether a is at least as large as both b and c.
  2. If not, test whether b is at least as large as both others.
  3. Otherwise return c.
  4. For 14, 22, 7, the a check fails and the b check succeeds.
  5. 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;
}

How It Works

  1. Outer choice: is a >= b?
  2. If yes, pick the larger of a and c.
  3. If no, pick the larger of b and c.
  4. Here 14 >= 22 is false, so compare 22 and 7.
  5. 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;
}

How It Works

  1. scanf reads three integers into a, b, and c.
  2. If fewer than three values are read, print an error and exit.
  3. Call the same biggest helper from Example 1.
  4. Input and comparison stay separate — easy to test.
  5. 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.

Time and Space Complexity

ProgramTimeExtra space
If-else ladderO(1)O(1)
Nested ternaryO(1)O(1)
User input + helperO(1)O(1)

Three comparisons (at most) — constant work for a fixed count of inputs.

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.

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.

13 people found this page helpful