How to use ‘else if ladder’ conditional statement is C language?

CServer Side ProgrammingProgramming

Else − if the ladder is the most general way of writing a multi-way decision.

The syntax for else if the ladder is as follows −

if (condition1)
else if (condition2)
   - - - - -
   - - - - -
   else if (condition n)
      stmt x;


Refer the flowchart given below −


Following is the C program to execute Else If Ladder conditional statement −

 Live Demo

void main (){
   int a,b,c,d;
   printf("Enter the values of a,b,c,d: ");
      printf("%d is the largest",a);
   else if(b>c){
      printf("%d is the largest",b);
   else if(c>d){
      printf("%d is the largest",c);
      printf("%d is the largest",d);


When the above program is executed, it produces the following result −

Enter the values of a,b,c,d: 2 3 4 5
5 is the largest
Published on 08-Mar-2021 15:05:00