Else-If Ladder Statement: Else-If ladder statement is a
multi-way statement. The general
format of else-if ladder statement is:
Syntax: if(condition1)
{
Statements-1
}
else
if(condition2)
{
Statements-2
}
.
.
.
else
if(conditionn)
{
Statements-n
}
else
{
Statements-s
}
Next statements
Ø First condition1 is
evaluated. It produces either TRUE or
FALSE.
Ø If the condition1 outcome is
TRUE, then Statements-1 are executed and then control reaches to
Next statements.
Ø If the condition1 outcome is
FALSE, then control reaches to condition2 and is evaluated. If condition2 outcome is TRUE, then Statements-2 are executed and then control reaches to Next statements. If condition2 outcome is FALSE, then control
reaches to condition3 and so on.
/* PROGRAM
TO PRINT LARGEST NUMBER FROM THE GIVEN THREE NUMBERS */
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,z;
clrscr();
printf("\nEnter Three Numbers:");
scanf("%d%d%d",&x,&y,&z);
if(x>=y&&x>=z)
printf("\nMaximum Number:%d",x);
else if(y>=z)
printf("\nMaximum Number:%d",y);
else
printf("\nMaximum Number:%d",z);
}
No comments:
Post a Comment