C If else if Ladder statement

if else if Ladder

The general form of else-if ladder is,

Syntax:

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.

Example:

//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();
}

Output:

Command Prompt
Enter a Number: -5
Given Number is Negative


Subscribe us on Youtube

Share This Page on

Questions


Prosenjit | 17-Feb-2018 12:25:07 am

If my given number is any alphabet what will be the ans???


Shaki | 09-Aug-2018 08:07:44 pm

what is the working procedure of else if ladder or statement..??


Mahaboobbasha | 10-Sep-2018 08:38:19 pm

Write c program to find given number is a prime or not


Chandan Kumar malik | 30-Oct-2018 08:04:58 pm

Write a program to find smallest among three numbers by using else if ladder


Ask Question