Professional Documents
Culture Documents
Write a C program to find maximum number between three numbers using ladder if or nested
if. How to find maximum or minimum between three numbers using if else in C
programming. Finding maximum between three numbers using if statement in C program.
Logic to find maximum or minimum between three numbers in C program.
Example
Input
Input num1: 10
Input num2: 20
Input num3: 15
Output
Maximum is: 20
Required knowledge
Basic C programming, If else, Operators
Now, think logically if I gave a task to find maximum between three numbers a, b and c. How
will you find that? Let us get the step by step descriptive logic to find maximum between
three numbers.
1. Compare first two numbers a > b. If the statement is true. Then we only need to check
two more numbers for maximum i.e. a > c. If again it evaluates to true. Then a is
maximum otherwise c.
2. Suppose the statement a > b is false. Which means either b or c is maximum. Now
check one more condition b > c. It evaluates to true if b is maximum otherwise c.
There are various way to code this program. First let us observe this program using nested if
The above method is lengthy and not recommended. Below is the simplest and recommended
method to use for these types of program. It uses the relational as well as logical operator to
find maximum.
Like above case b is maximum only and only if b > a and b > c.
Finally c is maximum only if both the conditions c > a and c > b are true.
Let us not implement this using logical operator and ladder if else.