Loading, please wait...

Switch Statement

C provides the switch multiple-selection statement to handle such decision making. The switch statement consists of a series of case labels, an optional default case, and statements to execute for each case.

Figure

 

 

 

 

Example

/* C program to print day of week using switch case*/

#include <stdio.h>

int main()
{
int week;

/*Read week number from user*/
printf("Enter week number(1-7): ");
scanf("%d", &week);

switch(week)
{
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 input! Please enter week number between 1-7.");
}
return 0;
}

Output:

Enter week number(1-7) : 6

SATURDAY