{ A destination to learn coding }

Conditional Statements

Nested if

C allows you to nest if inside if. See the general form below.

  if(expression2) statement;
  else statement;

else statement;

According to the C99 standards, a compiler should at least support 127 level of nesting. However, you are hardly going to use nesting to that extent.

We can modify the grades program using nested if.
int main()
float a;
printf("Enter your percentage\n");

   if(a<40) printf("Fail")

   else if((a>=40)&&(a<50)) /*using logical operators*/
      printf("Pass Class");

   else if((a>=50)&&(a<60))
      printf("Second Class");

   else if((a>=60)&&(a<75))
      printf("First Class");

   else if((a>=75)&&(a<90))

   else printf("Merit");

else printf("Invalid input")

return 0;

Note the difference between the two codes and see how the nesting is used.

Try this
Finding greatest in three numbers using if-else if statements
C Codes