Nested if-else statement :
When a series of decisions are involved we may have to use more than if statement in nested form as follows :
if ( test -condition-1)
{
if ( test-cndition-2)
{
statement - 1
}
else
{
statement - 2
}
}
else
{
statement - 3
}
statement - x
The logic of execution is if the condition - 1 is false then the statement - 3 is executed otherwise it continues to perform the condition - 2. if the condition - 2 is true, the statement - 1 is executed otherwise statement statement - 2 is executed. it is shown in following flowchart
Consider the following example
if ( a>b)
{
if (a>c)
{
printf("%d",a);
{
else
printf("%d",c);
}
}
else
{
if(b>c)
{
printf("%d",b);
}
else
{
printf("%d,c");
}
}
In above exemple, greater number from a, b and c will be displayed.
Nice one
ReplyDeleteGood job
ReplyDelete