NESTED IF ELSE

if( logic  )

{

    if( logic )

  {

  }

    else

  {           

  }

}

  else

{

}

If else if

This code is to find the tax slab of a individual

 

Salary

Tax slab

0  -  500000

5%

500001  -   1000000

10%

1000001  -   2000000

20%

 

#include<stdio.h>

void main()

{

  int salary=1500000;

  if(salary>0 && salary>=500000)

  {

    printf(“5% taxslab”);

  }

  elseif(salary>500000 && salary>=1000000)

  {

    printf(“10% taxslab”);

  }

  elseif(salary>1000000 && salary>=2000000)

  {

    printf(“20% taxslab”);

  }

}

&& and:where we need all Boolean value to be true.

|| or:where we need one Boolean value true out of more then one.

! not:where we need all Boolean value to be false.

And operator

We need to use decision operator where salary >100000 and salary <200000.

if(salary>100000){

if(salary<200000){

printf(“your salary b/w 100000 and 200000”);

}

}

if(salary>100000 && salary<200000){

printf(“your salary b/w 100000 and 200000”);

}

 

Or operator

int salary=200000;

if(salary>100000)

{

  printf(“your salary more then 100000”);

}

  if(salary>200000){

  printf(“your salary more then 2 lac”);

}

  else

{

  printf(“your salary b/w 1lac and 2 lac”);

}  

  if(salary>100000 || salary>200000)

{

   printf(“your salary might be more then 2 lac”);

}