C if-else-if statement

if-else-if Statement OR else if Ladder :

Suppose we need to specify multiple conditions then we need to use multiple if statements like this –

voidmain(){int num =10;if( num >0)printf("\n Number is Positive");if( num <0)printf("\n Number is Negative");if( num ==0)printf("\n Number is Zero");}

which is not a right or feasible way to write program. Instead of this above syntax we use if-else-if statement.

Consider the Following Program –

voidmain(){int num =10;if( num >0)printf("\n Number is Positive");elseif( num <0)printf("\n Number is Negative");elseprintf("\n Number is Zero");}

Explanation :

In the above program firstly condition is tested i.e number is checked with zero. If it is greater than zero then only first if statement will be executed and after the execution of if statement control will be outside the complete if-else statement.

elseif( num <0)printf("\n Number is Negative");

Suppose in first if condition is false then the second condition will be tested i.e if number is not positive then and then only it is tested for the negative.

elseprintf("\n Number is Zero");

and if number is neither positive nor negative then it will be considered as zero.