C Programming
If else-if ladder
The if else ladder statement in C programming language is used to test
set of conditions in sequence. An if condition is tested only when all
previous if conditions in if-else ladder is false. If any of the
conditional expression evaluates to true, then it will execute the
corresponding code block and exits whole if-else ladder.
{
//body to execute
}
else if(condition)
{
//body to execute
}
else if(condition)
{
//body to execute
}
else if(condition)
{
//body to execute
}
......
else
{
// body to execute
}
Fig. If else if ladder |
Example:
Void main()
{
int num;
printf("Enter a no.:");
scanf("%d",&num);
if(num<=100)
{
printf("No is smaller than or equal to 100");
}
else if(num<=200)
{
printf("No is smaller than or equal to 200");
}
else if(num<=300){
printf("No is smaller than or equal to 300");
}
else if(num<=400){
printf("No is smaller than or equal to 400");
}
else if(num<=500)
{
printf("No is smaller than or equal to 500");
}
else
{
printf("No is greater than 500")
}
getch();
}
Input: Enter a no.: 600
Output : No is greater than 500
c programming