Defination
Are those statements which will depend on
condition for their execution.
Types of Conditional Statements
If condition
if-else condition
If-else ladder
Nested if-else
• if-else condition
• Nested if-else
• If-else ladder
2/10/2023 PRESENTATION TITLE 2
if evaluates to true. It does nothing when the
expression evaluates to false.
Else is used when we want some statements
to be executed when if evaluates to be false.
So if the condition is true, if is executed else ,
else is executed.
2/10/2023 6
if-else condition
Nested if-else
• if-else construct within either the
body of the if statement or the body
of an else statement or both. Thisis
called nesting‘ of ifs.
2/10/2023 PRESENTATION TITLE 9
WAP to find greatest of 3 numbers
using nested if-else
#include<stdio.h>
int main()
{
int a,b,c;
printf(“enter a,b,cn”);
scanf(“%d%d%d”,&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf(“%d is greatest”,a);
}
2/10/2023 11
else
{
printf(“%d is greatest”,c);
}
}else
{
if(b>c)
{
printf(“%d is greatest”,b);
}else
{
printf(“%d is greatest”,c);
}
}
Return 0;
}
If-else Ladder
• It is used to check multiple conditions.
• Every else is associated with its previous if.
• The last else goes to work only if all the
conditions fail.
• Even in else if ladder the last else is
optional.
2/10/2023 PRESENTATION TITLE 12