Nested If Statement


In C Programming Language,we use Nested if statement when we want to test multiple conditions.


Syntax of Nested if statement

if(condition)

{

if(condition)

{

Statement;

}

}


Simple Program of Nested if statement in C

find the greatest of three numbers in C


#include <stdio.h>

#include<conio.h>;

void main(){

{

int x,y,z;

clrscr();

printf(“Enter three Number:\n”);

scanf(“%d%d%d”,&x,&y,&z);

if(x>y)

{

if(x>z)

{

printf(“X is greatest Number:%d”,x);

}

else

{

printf(“Z is greatest Number:%d”,z);

}

}

else

{

if(y>z)

{

printf(“Y is greatest Number: %d”,y);

}

else

{

printf(“Z is greatest Numebr %d”,z);

}

}

getch();

}


Output
Enter three Number: 10 20 4
B is greatest Number 20