Else-Ladder in C

a decision is a chain of ifs in which the statement associated with each else is an if the following syntax of else ladder condition.

Syntax


if(condition1)
{
	statement1;
}	
else if(condition2)	
{
	statement2;
}	
else if(condition3)	
{
	statement3;
}
else if(condition n)
{
	statement n;
}
else
{
	default statement;
}
							

Example


#include<stdio.h>
#include<conio.h>

void main()
{
	int y;
	clrscr();
	
	printf("Enter Year:");
	scanf("%d",&y);
	
	if(y%400==0)
	{
		printf("Leap Year");
	}
	elseif(y%100=0)
	{
		printf("Not Leap Year");
	}
	elseif(y%4==0)
	{
		printf("Leap Year");
	}
	else
	{
		printf("Not Leap Year");
	}
	getch();
}							
							
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!