Skip to main content

example of nested-if statement

// syntax of nested if statement
/*if (condition 1) 
{
   // Executes when condition 1 is true
   if (condition 2) 
   {
      // Executes when condition 2 is true
   }
}
*/
#include <stdio.h> 

int main() { 
   int i = 10

   if (i == 10
   { 
// First if statement 
      if (i < 15
      printf("i is smaller than 15\n"); 

      // Nested - if statement Will only be executed if statement above  is true 
      if (i < 12
         printf("i is smaller than 12 too\n"); 
      else
         printf("i is greater than 15"); 
   } 

   return 0

Comments

Popular posts from this blog

example of typecasting in c

/*Type Casting in C Typecasting allows us to convert one data type into other. */ //simple example to cast int value into the float. #include <stdio.h>    int   main (){   float   f = ( float ) 9 / 4 ;     printf ( "f : %f \n " ,  f  );     return   0 ;   }