C Program to Print Day of Week (1 to 7)

Written: August 22, 2026

Weekday mapping is the classic switch statement drill: one integer in, one label out, plus a default for invalid input.

This walkthrough keeps the logic small and readable so you can type it, run it, and then change one input at a time to see what happens.

What you will build

You will read an integer 1–7 and print the matching day name.

  • Read day number
  • switch on the value
  • Print the weekday string
  • Handle default invalid input

Working C example

#include <stdio.h>

int main(void) {
    int d;
    printf("Enter day (1-7): ");
    scanf("%d", &d);

    switch (d) {
        case 1: printf("Monday\n"); break;
        case 2: printf("Tuesday\n"); break;
        case 3: printf("Wednesday\n"); break;
        case 4: printf("Thursday\n"); break;
        case 5: printf("Friday\n"); break;
        case 6: printf("Saturday\n"); break;
        case 7: printf("Sunday\n"); break;
        default: printf("Invalid day\n"); break;
    }
    return 0;
}

Advertisement

How the logic works

Read the program top to bottom: includes and main first, then the statements that change variables, then the print that proves the result.

If your output looks wrong, print the variables before and after the critical lines. That single habit catches most beginner bugs faster than rewriting the whole file.

If your lab uses Sunday = 1, shift the labels — the structure stays the same.

Advertisement

Common mistakes

Forgetting a semicolon, using the wrong format specifier in printf/scanf, and mixing up assignment (=) with comparison (==) are the usual culprits.

Compile with warnings enabled (`gcc -Wall`) so the compiler points at risky casts and unused variables before you chase them by hand.

Try this next

Change the sample inputs, add a second test case, and briefly note what stayed the same. Teaching yourself with tiny experiments sticks better than copying a longer program you never run.

When you can explain every line without looking, you are ready for the next exercise in the series.

Keep learning

If this walkthrough on day of week 1 to 7 c helped, open the code again and change one input or assumption. Small experiments beat rereading the same example.

Want more step-by-step tutorials like this? Browse blog.xqa.io — and tell us which topic you want next.

Advertisement

Previous Article

Check if a String Contains a Substring in JavaScript

Next Article

C Program to Check Prime Number

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨