Introduction: In the previous article i explained how to check the day corresponding to entered number using Else if ladder in C Language and How to swap two numbers without using temporary variable in C Language? and Check whether a number is positive or negative using if else in C Language and Check whether a number is even or odd using if else statement in C Language. In this article i am going to explain how to check the month name corresponding to entered number using ladder else if or we can say multiple else if in C language. Let's understand by creating a program.
#include<conio.h>
#include<conio.h>
#include<stdio.h>
main()
{
printf("Enter any number between 1 to 12 : ");
scanf("%d",&num);
if(num==1)
{
printf("JANUARY");
}
else if(num==2)
{
printf("FEBRUARY");
}
else if(num==3)
{
printf("MARCH");
}
else if(num==4)
{
printf("APRIL");
}
else if(num==5)
{
printf("MAY");
}
else if(num==6)
{
printf("JUNE");
}
else if(num==7)
{
printf("JULY");
}
else if(num==8)
{
printf("AUGUST");
}
else if(num==9)
{
printf("SEPTEMBER");
}
else if(num==10)
{
printf("OCTOBER");
}
else if(num==11)
{
printf("NOVEMBER");
}
else if(num==12)
{
printf("DECEMBER");
}
else
{
printf("INVALID NUMBER ...PLEASE ENTER NUMBER BETWEEN 1 TO 12");
}
getch();
}
Run the program using Ctrl+F9
Output:
First Run
Enter any number between 1 to 12 : 7
JULY
Second Run
Enter any number between 1 to 12 : 11
NOVEMBER
Third Run
Third Run
Enter any number between 1 to 12 : 15
INVALID NUMBER ...PLEASE ENTER NUMBER BETWEEN 1 TO 12
If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..