Introduction: In previous articles i explained the program for How to find week days corresponding to number using switch case in C Language and Else if ladder or multiple else if to check the day corresponding to number in C Language and Else if ladder or multiple else if to check the month of entered number in C language.
In this post i have written a program to check the month name corresponding to entered number using switch case statement in C Language.
The switch statement is a control statement that handles multiple selections by passing control to one of the case statements within its body.
It accepts single input from the user and based on that input executes a particular block of statements. Control passes to the statement whose case constant-expression matches the value of switch (expression).
Let's create a program to understand the concept.
In this post i have written a program to check the month name corresponding to entered number using switch case statement in C Language.
The switch statement is a control statement that handles multiple selections by passing control to one of the case statements within its body.
It accepts single input from the user and based on that input executes a particular block of statements. Control passes to the statement whose case constant-expression matches the value of switch (expression).
Let's create a program to understand the concept.
#include<conio.h>
main()
{
int num;
clrscr();
printf("Enter any number between 1
to 12: ");
scanf("%d",&num);
switch(num)
{
case 1:
printf("January");
break;
case 2:
printf("February");
break;
case 3:
printf("March");
break;
case 4:
printf("April");
break;
case 5:
printf("May");
break;
case 6:
printf("June");
break;
case 7:
printf("July");
break;
case 8:
printf("August");
break;
case 9:
printf("September");
break;
case 10:
printf("October");
break;
case 11:
printf("November");
break;
case 12:
printf("December");
break;
default:
printf("INVALID NUMBER!!! Please enter
number between 1 to 12");
}
getch();
}
OUTPUT
First Run:
Enter any number between 1 to 12 :
10
October
Second 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..