Else If Ladder Statement In C++


Else if ladder statement is another way to test condition. It check multipath decision involved in statement.


Syntax of else if ladder statement

if(condition)

{

statement;

}

else if(condition)

{

statement;

}

else if(condition)

statement;

}

. . . . .

/* else here optional it’s depend’s on you */

else

{

statement

}


Simple Example Of Ladder If Else Statement In C++

Print the greatest Number between three Number.


#include <iostream>

#include<using namespace std;>

int main(){

int a,b,c;

clrscr();

cout<<“Enter three Number:\n”;

cin>>a>>b>>c;

if(a>b && a>c)

{

cout<<“A is greatest Number:”<

}

else if(b>c)

{

cout<<“B is greatest Number: ”<

}

else

{

cout<<“C is greatest Number:”<

}

return 0;

}


Output:
Enter three Number 10   2   30

C is greatest Number: 30