C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Decision Making Programs in C

Print day of week (switch-case)

Introduction

In C programming, the switch-case statement is ideal when you have a fixed number of choices.
For example, when a user enters a number from 1 to 7, each number can represent a day of the week:

  • 1 → Sunday
  • 2 → Monday
  • 3 → Tuesday
  • 4 → Wednesday
  • 5 → Thursday
  • 6 → Friday
  • 7 → Saturday

This program takes an integer input and prints the corresponding day using a switch-case statement.

 

C Program: Print day of week (switch-case)

C

#include <stdio.h>

 

int main() {

    int day;

 

    // Input day number

    printf("Enter day number (1-7): ");

    scanf("%d", &day);

 

    // Switch-case to print day name

    switch (day) {

        case 1:

            printf("Sunday\n");

            break;

        case 2:

            printf("Monday\n");

            break;

        case 3:

            printf("Tuesday\n");

            break;

        case 4:

            printf("Wednesday\n");

            break;

        case 5:

            printf("Thursday\n");

            break;

        case 6:

            printf("Friday\n");

            break;

        case 7:

            printf("Saturday\n");

            break;

        default:

            printf("Invalid input! Please enter a number between 1 and 7.\n");

    }

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter day number (1-7): 4
Wednesday

OUTPUT 2 :
Enter day number (1-7): 7
Saturday

OUTPUT 3 :
Enter day number (1-7): 9
Invalid input! Please enter a number between 1 and 7.

Explanation

  1. The user enters a number between 1 and 7.
  2. The switch statement matches the number with a case.
  3. Each case prints the corresponding day name.
  4. If the input does not match any case (1–7), the default case is executed.