C program to print day of week name using switch case

Write a C program to enter week number(1-7) and print day of week name using switch case. C program to find week day name using switch case. Logic to find day name of week using switch case in C program.

Example
Input

Input week number(1-7): 2

Output

Tuesday

Required knowledge

Basic programming, Switch case

Logic to print day name of week using switch case

Below is the step by step descriptive logic to print day name of week.

  1. Input day number from user, store it in some variable say week.
  2. Switch the value of week and match with cases.
  3. For case 1 print "MONDAY", for case 2 print "TUESDAY" and so on. Print "SUNDAY" for case 7.
  4. For default case print "Invalid week number".

Let us code solution for the given program.

Program to print day name of week using switch case

/**
 * 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;
}

Note: Here we are assuming Monday as the first day of week. Hence if week number is 1 output will be Monday and so on.

Practice this program using if else.

Read more - Program to find day name of week using if else

Output

Enter week number(1-7): 1
MONDAY

Happy coding 😉

Write your doubts or suggestion. I will try my best to help. You must escape source code before commenting. To format your source code paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>