Course Content
History of C Language
0/2
Basic Structure of C Program
0/1
Types of Errors
0/1
Language Fundamentals
0/1
Data Types and Modifiers
0/1
Programming with C Language
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");

}

You cannot copy content of this page