The general form of else-if ladder is,
if(expression 1)
{
statement-block1;
}
else if(expression 2)
{
statement-block2;
}
else if(expression 3)
{
statement-block3;
}
else
default-statement;
The expression is tested from the top (of the ladder) to downwards. As soon as the true condition will found, the statement associated with it is executed.
//Write a C Program which demonstrate use of if-else-if ladder statement.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Enter a Number: ");
scanf("%d",&a);
if(a > 0)
{
printf("Given Number is Positive");
}
else if(a == 0)
{
printf("Given Number is Zero");
}
else if(a < 0)
{
printf("Given Number is Negative");
}
getch();
}
Ask Question