Else - If ladder is the most general way to write multi-way decisions.
else if syntax for ladder is as follows-
if (condition1) stmt1; else if (condition2) stmt2; - - - - - - - - - - else if (condition n) stmtn; else stmt x;
Please refer to the flowchart given below-
The following is a C program that executes the Else If Ladder conditional statement-
Live demonstration
#include<stdio.h> void main (){ int a,b,c,d; printf("Enter the values of a,b,c,d: "); scanf("%d%d%d%d",&a,&b,&c,&d); if(a>b){ 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); } else{ printf("%d is the largest",d); } }
When the above program is executed, produces the following results -
Enter the values of a,b,c,d: 2 3 4 5 5 is the largest
The above is the detailed content of How to use 'else if ladder' conditional statement in C language?. For more information, please follow other related articles on the PHP Chinese website!