Nested if-else Statement in C Language
Nested if statement in C programming language is placing if statement within another if statement with an else statement. Whenever the if statement return true then the inner if statement will be executed. The following example explains the concept of nested if else block. The syntax for nested if-else statement is as follows:-
if(condition1)
{
//when if condition1 evaluates result as true then it will check for condition2
if(condition2)
{
Statements ; //when if condition2 evaluates result as true
}
else
{
Statements ; //when if condition2 evaluates result as false
}
}
else
{
Statements ; //when if condition1 evaluates result as false
}
#include<stdio.h>
#include<conio.h>
void main()
{
int no1, no2, no3;
printf("Enter Number 1 : ");
scanf("%d",&no1);
printf("Enter Number 2 : ");
scanf("%d",&no2);
printf("Enter Number 3 : ");
scanf("%d",&no3);
if(no1>no2)
{
if(no1>no3)
{
printf("Number 1 : %d is larger than Number 2 and Number 3",&no1);
}
else
{
printf("Number 3 : %d is larger than Number 1 and Number 2",&no3);
}
}
else
{
if(no2>no3)
{
printf("Number 2 : %d is larger than Number 1 and Number 3",&no2);
}
else
{
printf("Number 3 : %d is larger than Number 1 and Number 2",&no3);
}
}
getch();
}
Flow Chart of Nested if else Statement

