Else If statement with simple program

Else If statement provides us the way to use many If statements in a single program. This sequence of if statements is the most general way of writing a multi-way decision. The expressions are evaluated in order; if an expression is true, the statement associated with it is executed, and this terminates the whole chain. As always, the code for each statement is either a single statement, or a group of them in braces.

The last else part handles the “none of the above” or default case where none of the other conditions is satisfied. Sometimes there is no explicit action for the default.

The general form of syntax is

if (condition 1)
simple or compound statement
else if (condition 2)
simple or compound statement
else if ( condition 3)
simple or compound statement
…..
else if ( conditon n )
simple or compound statement

else if

Program to illustrate use of Else if statement

#include <stdio.h>

#include<conio.h>

main()

{
int i ;

Printf(“ Enter any value : “ \t);

Scanf( “%d”,&i);

if (i == 0)

{
printf(” You have entered zero \n”);
}

else if (i == 1)

{
printf(” You have entered one  \n”);
}

else if

(i == 2)

{
printf(” You have entered two  \n”);
}

Else

{

Printf(“ Enter number between 0 to 2 “);

}

getch();

}

Mohit Arora
Follow me