Find Maximum of 3 Numbers in C, C++, Java & Python – Code with Explanation & Examples in Short and Simple

  

C Program

#include<stdio.h>

int main() {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int max = (a > b ? (a > c ? a : c) : (b > c ? b : c));
    printf("%d", max);
}

C Output

Input: 5 9 3  
Output: 9


C++ Program

#include<iostream>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int max = (a > b ? (a > c ? a : c) : (b > c ? b : c));
    cout << max;
}

C++ Output

Input: 12 7 15  
Output: 15


JAVA Program

import java.util.*;

class M {
    public static void main(String[] a) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(), y = sc.nextInt(), z = sc.nextInt();
        int max = (x > y ? (x > z ? x : z) : (y > z ? y : z));
        System.out.print(max);
    }
}

JAVA Output

Input: 45 67 29  
Output: 67


Python Program

a, b, c = map(int, input().split())
print(max(a, b, c))

Python Output

Input: 8 3 5  
Output: 8


In-Depth Learning – Whole Concept in Paragraphs
What Does "Finding the Maximum of 3 Numbers" Mean?
Finding the maximum of three numbers involves finding the biggest number out of the three provided values. It is a basic programming concept that introduces comparisons, decision-making, and conditional logic.

This issue develops your skill in comparing several conditions and coming to a result on the basis of relative logic. It's most frequently encountered in interviews, aptitude tests, and initial learning exercises.

How It Works
We have three inputs — let's refer to them as a, b, and c.
With ternary operators (or Python's built-in max() function), we pair up the values and compare them:

Compare a with b

The greater of those is then compared against c

Final output is the biggest among all three.

This prevents writing lengthy if-else blocks and makes the code both neat and efficient.

Example
Suppose a = 5, b = 9, c = 3

Initial comparison: a > b → 5 > 9 → False → So b is greater

Now compare b and c → 9 > 3 → True → So the output is 9

Python simplifies it further using:

python
Copy
Edit
max(a, b, c)
Which does the same thing internally but more graciously.

Real-Life Analogy
Consider three people on various steps of a podium. You would like to know who is on top. You compare the first two and select the taller individual, then compare that to the third. The remaining one is the tallest — just like our program finds the maximum number.

This concept is also used in real-world cases like:

Leaderboard ranking

Scoring systems

Sensor value comparisons (e.g., max temperature of three locations)

Why This Problem Is Important
This is a foundation-level logic problem that helps learners understand:

Comparison operators (>, <)

Conditional logic using if-else or ternary operators

Nested conditions

Built-in functions (max())

You’ll see this concept often in sorting algorithms, decision trees, and mathematical modeling where multiple values need comparison.

It’s also widely asked in:

Entry-level programming interviews

MCQ-based coding assessments

College-level practical exams

Python-Specific Advantage
Python's built-in max() function makes it so straightforward and elegant. It facilitates comparison of more than two values simultaneously, which is very useful when the number of inputs gets larger. This is an ideal way of providing function-based thinking in Python.

SEO-Optimized Natural Paragraph for Ranking
Want to find the biggest among three numbers? This tutorial explains the easiest and most elegant way to get the maximum of three numbers with C, C++, Java, and Python. Whether you're learning about conditionals, preparing for tech interviews, or simply practicing comparisons, this exercise shows you how to make intelligent decisions in your code. With down-to-earth logic, everyday analogies, and effective deployment of language-specific facilities such as ternary operators and built-in functions, this tutorial makes it easy for students to master one of the most basic programming concepts — obtaining the max value from a set of inputs.