Table of Contents
show
if… else if… else
Syntax
if(condition 1):
Statement 1
else if(condition 2):
Statement 2
else if(condition 3):
Statement 3
else:
Default statement
Flowchart
Example
#include<stdio.h>
int main()
{
int n1,n2;
printf("Enter two integers \t");
scanf("%d%d",&n1,&n2);
if(n1 == n2)
{
printf("Result:%d = %d",n1,n2);
}
else if(n1 > n2)
{
printf("Result:%d > %d",n1,n2);
}
else
{
printf("Result:%d < %d",n1,n2);
}
return 0;
}
Output
Enter two integers 2 4
Result: 2 < 4
Views: 0