Q:

C program to read weekday number and print weekday name using switch

0

C program to read weekday number and print weekday name using switch

This program will read weekday number (0-6) and print weekday name (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday) according to given weekday number using switch case statement in c programming language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Print weekday name program according to given weekday number using switch

/*C program to read weekday number and print weekday name using switch.*/
 
#include <stdio.h>
 
int main()
{
    int wDay;
     
    printf("Enter weekday number (0-6): ");
    scanf("%d",&wDay);
     
    switch(wDay)
    {
        case 0: 
            printf("Sunday");
            break;
        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;
        default:
            printf("Invalid weekday number.");
    }
    printf("\n");
    return 0;
}

Output

    First Run:
    Enter weekday number (0-6): 3
    Wednesday

    Second run:
    Enter weekday number (0-6): 9
    Invalid weekday number.  

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to read gender (M/F) and print correspon... >>