C Program to display day of week using switch case in C Language

 

C Program to display day of week using switch case in C Language


/*********************************************************************

 C Program to display day of week using switch case in C Language

 ********************************************************/

#include<stdio.h>

#include<conio.h>

void main()

{

    char day;

clrscr();

    printf("The choices to select day of week are as given below,\n");

    printf("M or m : Monday\n");

    printf("T or t : Tuesday\n");

    printf("W or w : Wednesday\n");

    printf("H or h : Thursday\n");

    printf("F or f : Friday\n");

    printf("S or s : Saturday\n");

    printf("U or u : Sunday\n");

    printf("Enter your choice\n");

    scanf("%c",&day);

    switch(day)

    {

        case 'M':

        case 'm':

        printf("The selected day is Monday\n");

        break;

        case 'T':

        case 't':

        printf("The selected day is Tuesday\n");

        break;

        case 'W':

        case 'w':

        printf("The selected day is Wednesday\n");

        break;

        case 'H':

        case 'h':

        printf("The selected day is Thursday\n");

        break;

        case 'F':

        case 'f':

        printf("The selected day is Friday\n");

        break;

        case 'S':

        case 's':

        printf("The selected day is Saturday\n");

        break;

        case 'U':

        case 'u':

        printf("The selected day is Sunday\n");

        break;

        default:

        printf("Please enter valid choice");

    }

}


The choices to select day of week are as given below,

M or m : Monday

T or t : Tuesday

W or w : Wednesday

H or h : Thursday

F or f : Friday

S or s : Saturday

U or u : Sunday

Enter your choice

F

The selected day is Friday


In above program character case constant is used. Two characters capital and small letters are used to find the day of week. User may have choice capital character or small character so two character for same case constant is given as above. day variable is character variable and it is used as switch case expression. Every character is enclosed in single quotation.


टिप्पणी पोस्ट करा

0 टिप्पण्या