Nested If Statement in C Language

  • Nested if statements mean an if statement inside another if statement
  • Nested If in C is helpful if you want to check the condition inside a condition

Syntax:

if (test_expression one)
{
                if (test_expression two)
                {
                   //Statement block Executes when the Boolean test expression two is true.
                }
}
else
{
//else statement block
}

For Example,

Write a C program to find the given voter is eligible for voting or not

#include <stdio.h>
#include <conio.h>
void main()
{
int age;
printf(\”Please Enter Your Age Here:\\n\”);
scanf(\”%d\”,&age);
if ( age < 18 )
{
printf(\”You are Minor.\\n\”);
printf(\”Not Eligible to Work\”);
}
else
{
if (age >= 18 && age <= 60 )
{
printf(\”You are Eligible to Work \\n\”);
printf(\”Please fill in your details and apply\\n\”);
}
else
{
printf(\”You are too old to work as per the Government rules\\n\”);
printf(\”Please Collect your pension! \\n\”);
}
}
getch();
}