Nested If Statement In C++


When We Want To Test Multiple Condition Then We Use Nested If Statement In C++


Syntax of Nested if statement

if(condition)

{

if(condition)

{

Statement;

}

}


Simple Example Of Nested If Statement In C++

Find The Greatest Number Between Three Number


#include<iostream>

using namespace std;

int main(){

int a,b,c;

cout<<“Enter three Number:”;

cin>>a>>b>>c;

if(a>b)

{

if(a>c)

{

cout<<“A is greatest Number:”<

}

else

{

cout<<“C is greatest Number:”<

}

}

else

{

if(b>c)

{

cout<<“B is greatest Number:”<

}

else

{

cout<<“C is greatest Numebr:”<

}

}

return 0;

}


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