Else If Ladder Statement In C


In C Programming Language one of the other way to check condition is Else if ladder statement. It checks multipath decision involved in the statement.


Syntax of else if ladder statement

if(some_condition)

{

statement;

}

else if(some_condition)

{

statement;

}

else if(some_condition)

statement;

}

. . . . .

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

else

{

statement

}


Simple Program of Ladder if else statement in C

Print the greatest of three Number.


#include <stdio.h>

#include<conio.h>

void main()

{

int x,y,z;

clrscr();

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

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

if(x>y && x>z)

{

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

}

else if(y>z)

{

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

}

else

{

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

}

getch();

}


Output:
Enter three Number 10   2   30

Y is greatest Number: 30