Monday, 17 September 2012

Nested If


In nested-if statement if the first if condition is true the control will enter inner if. If this is true the statement will execute otherwise control will come out of the inner if and the else statement will be executed.
Syntax:
If (condition)
if(condition)
{
    statement(s);
}
else
{
   statement(s);
}
else
{
statement(s);
}
Flowchart


Example:
#include<stdio.h>
#include<conio.h>
void main ()
{
int a,b,c;
clrscr();
printf("Enter three number:");
scanf("%d %d %d,&a,&b,&c);
if (a<b)
            if (a>c)
        printf("%d is a smallest number.",a);
        else
            printf("%d is a samallest number.",c);
        else
            if(b<c)
        printf("%d is smallest number.",b);
else
printf("%d is smallest number.",c);
getch();
}

No comments:

Post a Comment