Course Content
History of C Language
0/2
Basic Structure of C Program
0/1
Types of Errors
0/1
Language Fundamentals
0/1
Data Types and Modifiers
0/1
Programming with C Language
About Lesson

else if
this is used when we want to check further condition when the given condition is returned false.

//example program else if

#include<stdio.h>

void main()
{
int x=10;

if(x<0)
{
printf("%d is negative number",x);
}
else
{
if(x%2==0)
{
printf("n%d is even natural number",x);
}
}
printf("nRest of code in main");

}

else if ladder
When the checking of further condition when a condition is returned false propagating, then it makes a ladder like pattern.

//example program else if ladder

#include<stdio.h>

void main()
{
int x;

printf("Enter any number for 2,4,6 or 8 :");
scanf("%d",&x);

if(x==2)
{
printf("TWO");
}
else
{
if(x==4)
{
printf("FOUR");
}
else
{
if(x==6)
{
printf("SIX");
}
else
{
if(x==8)
{
printf("EIGHT");
}
else
{
printf("Invalid Input");
}
}
}
}

printf("nRest of code in main");

}

when we are creating nested blocks, the inner most block to be closed first. For each opening brace there must be ending brace.

putting single statement under Curly brace is optional when we are defining block.

You cannot copy content of this page