Nested if-else Statements in C

For Complete YouTube Video: Click Here

In this class, we will try to understand Nested if-else Statements in C.

We have already discussed if-else statements.

As per our discussion, it is not mandatory to use else statement with an every if statement.

Nested if-else

Nested if-else means an if-else statement used within another if-else.

The image below is the program to understand Nested if-else.

Nested if-else Statements in C 1
Nested if-else Statements in C

In the above program, an if-else statement is used within another if-else.

The above is to find the largest among the three numbers.

The a, b, and c are integer type variables with values 5, 4, and 3.

We will understand the logic by using the program.

The outer if statement is to check the largest between a and b.

If a > b is valid means among a and b, a is larger.

Now we have to compare the value of a with c, which is checked in the nested if statement.

If a > c is valid, means among a, b, and c a is larger.

If a > c is NOT valid, means among a, b, and c, c is larger.

If a > b is NOT valid means among a and b, b is larger.

We have to compare the value of b with c, which is checked in the nested if statement in the else part.

If b > c is valid, means among a, b, and c b is larger.

If b > c is NOT valid, means among a, b, and c, c is larger.