An illustration of a nested if else statement in C language with a flowchart and code example.

The diagram mentions that it is a flow chart for a nested if-else. It defines using structure in C programming for determining the larger one among any three values. For our stepwise discussion, we will consider the values as: a = 5, b = 7, c = 4.

Let's go through the flowchart:
First Check: We start testing whether a > b. In our case (5 > 7) this condition is false. Next Decision: If the first condition were false, that flow would be about b > c. This condition holds true for our values (7 > 4).

Maximum Found: Since b > c holds true, therefore flowchart identifies b (which is 7) as maximum. This flow chart is designed so robust; it will be working just fine with all possible combinations of three numbers and will surely mark the maximum.
Here are various combinations for which this flow chart will find out maximum value:
a=5, b=7, c=4
a=5, b=4, c=7
a=7, b=4, c=5
a=7, b=5, c=4
a=4, b=5, c=7
a=4, b=7, c=5


Example 1: C program to illustrates the use of Nested if-else statement .

/* C program to find maximum number out of given three number */
#include<stdio.h>
int main()
{
int a,b,c;
printf("\n Enter any Three numbers");
scanf("%d %d %d",&a,&b,&c);
if(a>b)
 {
   if(a>c)
    {
     printf("\n %d is maximum",a);
    }
   else
    {
      printf("\n %d is maximum",c);
     }
 }
else
 {
   if(b>c)
   {
    printf("\n %d is maximum",b);
   }
  else
   {
     printf("\n %d is maximum",c);
    }
 }
return(0);
}


Output:
Enter any Three number.
5
7
4
7 is maximum.
Programm Explanation:
It is this input that is passed against the program: a = 5, b = 7, c = 4.
1.First Condition: if (a > b): The program checks (5 > 7), and false.
2.Proceed Else: (if False then goto else): It passes over first if block to their else blocks because a is not greater than b.
3.Nested Condition (if (b > c) within else): It now checks b > c within Else. i.e. if (7 > 4) is true.
4.Maximum Print: So b > c evalutes True and the code inside this inner if block is executed. The result is 7 is maximum.
Hence, the number found by the program is maximum across inputs.


Previous Topic:-->> if else ladder statement in C || Next topic:-->>switch case in C.


Other Topics
SQL Interview Questions Java Interview QuestionsTop SQL Interview QuestionsPython Interview QuestionsBanking Case Study in SQL