Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Input/Output statements
  5. Decision making statement...
  6. if… else if… else

if… else if… else

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

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments