Home / Programs / Nested if-else in c programming langauge
Programming Example

Nested if-else in c programming langauge

👁 5,982 Views
💻 Practical Program
📘 Step by Step Learning

In this example of c program you will how to use nested if in c programming Language.

Program Code

#include"stdio.h"
int 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");
   }
 }
 
 return 0;
}

Output

Please Enter Your Age Here:
55
You are Eligible to Work
Please fill in your details and apply
Press any key to continue . . .

Explanation

In this example of c program you have learned that, how to use nested if in c programming Language.

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.