ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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.

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.  

C Switch Case Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.