WHAT'S NEW?
Loading...

Nested if-else Statement in C

The if-else construct may contain other if or if-else constructs, a feature called nesting. We must be careful in this case, as we have to keep track of the different ifs and the corresponding elses. 
Syntax: 
          if(conditional_expression)
          {
                     if(conditional_conditional_expression-1){
                                statement(s);
                     } else {
                                statement(s);
                     }
           } else {
                      statement(s);
            }

Example: 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include<stdio.h>
void main(){
 int com, math; 
 com = 55; 
 math = 44; 
 if(com>=50){
  if(math>=50){
   printf("You are selected !!"); 
  } else {
   printf("You are not selected !!"); 
  }
 } else {
  printf("Sorry !! you are not selected !!"); 
 }
 getch(); 
}


Output
You are not selected !!

0 comments:

Post a Comment