About Lesson
Nested if
one if statement under the control of another if. Inner if appears insides the True part of outer if.
//example program of Nested if
#include<stdio.h>
void main()
{
int x=10;
if(x>0)
{
if(x%2==0)
{
printf("%d is even natural number",x);
}
}
printf("\nRest of code in main");
}
there can be other statements too inside outer if along with ‘inner if’
inner if can also be if…else
//example program 2 of Nested if
#include<stdio.h>
void main()
{
int x=10;
if(x>0)
{
printf("%d is natural number",x);
if(x%2==0)
{
printf("\n%d is even natural number",x);
}
else
{
printf("\n%d is odd natural number",x);
}
printf("\nRest of code in Outer if");
}
else
{
printf("%d is not natural number",x);
}
printf("\nRest of code in main");
}