C program to Find the Largest Number Among Three Numbers

Last Updated : 17 Aug, 2026

Given three integer numbers, the task is to find the largest number among them.

  • The program compares the three numbers using conditional statements.
  • The number greater than or equal to the other two numbers is considered the largest.

Examples

Input: a = 10, b = 22, c = 19
Output: 22 is the largest number.
Explanation: Among the numbers 10, 22, and 19, the largest number is 22.

Input: a = 12, b = 7, c = 9
Output: 12 is the largest number.
Explanation: Among the numbers 12, 7, and 9, the largest number is 12.

Finding the Largest Number Among Three Numbers

The basic method to find the largest number among three numbers is by using an if statement to compare the numbers with each other in pairs. Let's consider three numbers a, b, and c:

  • Check if a is greater than b and a is also greater than c. If both conditions are true, a is the largest.
  • Otherwise, c is the largest.
  • If a is not greater than b and b is greater than or equal to c, b is the largest.
  • Otherwise, c is the largest.

Flowchart of the Logic

largest-among-three-numbers

Largest of Three Numbers Using if-else Statement

C
#include <stdio.h>

int main()
{
    int c = 10, b = 22, a = 9;

    // Finding largest by comparing using relational operators
    if (a >= b) {
        if (a >= c)
            printf("%d is the largest number.", a);
        else
            printf("%d is the largest number.", c);
    }
    else {
        if (b >= c)
            printf("%d is the largest number.", b);
        else
            printf("%d is the largest number.", c);
    }

    return 0;
}

Output
The numbers A, B and C are: 10, 22, 9
22 is the largest number.

Other Different Methods to Find the Largest of Three Numbers

There are many different ways using which we can find the largest number between three numbers:

1. Using Compound Expression in if-else

We can compare a number with other two number in a single if statement using AND operator. It allows us to combine the two relational expressions from the above program making the program concise.

C
#include <stdio.h>

int main() {
    int a = 11, b = 2, c = 9;

    // Finding max using compound expressions
    if (a >= b && a >= c)
        printf("%d is the largest number.", a);
    else if (b >= a && b >= c)
        printf("%d is the largest number.", b);
    else
        printf("%d is the largest number.", c);

    return 0;
}

Output
The numbers A, B and C are: 10, 22, 9
22 is the largest number.

2. Using Temporary Variable

We assume one of the numbers as maximum and assign it to a temporary variable. We then compare this temporary variable with the other two numbers one by one and if the max is smaller than the compared number, we assign the compared number to the max.

C
#include <stdio.h>
int main() {
    int a = 10, b = 22, c = 9;

    // Assume a is the largest
    int max = a;

    // If b is larger than max
    if (max < b)
        max = b;

    // If c is larger than max
    if (max < c)
        max = c;

    printf("%d is the largest number.", max);
    return 0;
}

Output
The numbers A, B and C are: 10, 22, 9
Maximum among 10, 22, and 9 is: 22

3. Using a Custom Max Function

We can define a max() function that takes two numbers and return the greater one. We can use this function to find the largest among three number by first using max with two numbers and then using it with third number.

C
#include <stdio.h>

// Custom function to find the maximum of two numbers
int findMax(int b, int a) {

    // Return a if a is greater than or equal to b, else
    // return b
    return (a >= b) ? a : b;
}

int main() {
    int a = 10, b = 22, c = 9;

    // Calling max function for the first two numbers and then
  	// for its returned value and third number.
    int max = findMax(max(a, b), c);

    printf("%d is the largest number.", max);

    return 0;
}

Output
The numbers A, B and C are: 10, 22, 9
The largest number is 22
Comment