Simple C Program for Switch case to Find weekdays name with weekday number

Definition

In c programming language, switch statement is a type of selection mechanism used to allow block code among many alternatives.

Simply,It changes the control flow of program execution via a mutliple block. we can use for Nested if.. else statement.

Syntax:

switch ( <variable> ) {
	case value1:
	 //Block 1 Code Here
	 break;

	case value2:
	 //Block 1 Code Here
	 break;
	...

	default:
	 Code to execute for not match case
	 break;
}

Simple C Program for Switch case to Find weekdays name with weekday number

/*## Simple C Program for Switch case to Find weekdays name with weekday number */
/*## Basic Programs,Find weekdays C Programming*/


#include <stdio.h>
 
int main() {

	// Declare Variables
    int day;
    
    //Read Day Value
    printf("Enter weekday number (1-7): ");
    scanf("%d",&day);
     
    //Print Day with Switch case
    switch(day)
    {
        case 1: 
            printf("1 - Sunday");
            break;
        case 2: 
            printf("2 - Monday");
            break;
        case 3: 
            printf("3 - Tuesday");
            break;
        case 4: 
            printf("4 - Wednesday");
            break;
        case 5: 
            printf("5 - Thursday");
            break;
        case 6: 
            printf("6 - Friday");
            break;
        case 7: 
            printf("7 - Saturday");
            break;
        default:
            printf("%d : Invalid Day Option",day);
    }
   
	return 0;
}

Sample Output:

Enter weekday number (1-7): 4
4 - Wednesday

Enter weekday number (1-7): 10
10 : Invalid Day Option