Pages

Hello there!

Powered by Blogger.

Monday, January 7, 2013

ELSE IF STATEMENT IN C


ELSE IF STATEMENT IN C WITH EXAMPLE


else if statement is used when multipath decision are involved.

Syntax:-

if(condition 1)
{
statement 1
}
else if (condition 2)
{
statement 2
}
else if (condition 3)
{
statement 3
}
.
.
.
else if (condition N)
{
statement N
}
statement

Note:-

# Condition can be expression or relation.
# If body of statement is only one statement than braces ({}) are not needed.
# Body of the statement may have one or more statement.
# Any one statement is executed not all.

Execution:-

The conditions are checked from top to bottom when true condition is found than statement related to that condition is executed and control is transfer to statement next to else is statement
when all condition are false than statement related to else is executed and control is transfer to statement next to else is statement

Examples:-

Program to solve following problem

Average marks Grade
100-75 1
74-50 2
49-30 3
29-30 4

0 comments:

Post a Comment