Home / Programs / Program to use switch statement. Display Monday to Sunday.
Programming Example

Program to use switch statement. Display Monday to Sunday.

👁 15,393 Views
💻 Practical Program
📘 Step by Step Learning
Program to use switch statement. Display Monday to Sunday.

Program Code

/* Program to use switch statement. Display Monday to Sunday.
  Author: Atnyla Developer */
  
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
 
printf("enter m for Monday \nt for Tuesday\nw for Wednesday\nh for Thursday\nf for Friday\ns for Saturday\nu for Sunday \n");
printf("...............");
scanf("%c",&ch);

switch(ch)
{
case 'm':
case 'M': 
	printf("monday \n");
break;
case 't':
case 'T':
printf("tuesday \n");
break;
case 'w':
case 'W':
	printf("wednesday \n");
break;
case 'h':
case 'H':
	printf("thursday \n");
break;
case 'f ':
case 'F':
	printf("friday \n");
break;
case 's':
case 'S':
	printf("saturday \n");
break;
case 'u':
case 'U':
	printf("sunday \n");
break;
default: 
	printf("wrong input \n");
break;
}
getch();
}

Output

enter m for Monday
t for Tuesday
w for Wednesday
h for Thursday
f for Friday
s for Saturday
u for Sunday
...............m
monday
Press any key to continue . . .

Explanation

Program to use switch statement. Display Monday to Sunday.

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.