Introduction: In previous articles i explained the program for 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 week day 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.
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 7: ");
scanf("%d",&num);
switch(num)
{
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
default:
printf("INVALID NUMBER!!! Please enter
number between 1 to 7");
}
getch();
}
OUTPUT
First Run:
Enter any number between 1 to 7: 5
Saturday
Second Run:
Enter any number between 1 to 7: 9
INVALID NUMBER !!! Please enter number between 1 to 7
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..