Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

C Program to Print Day of the Week Using Enum and Switch

Day of the Week Using Enum and Switch in C

✅ C Program to Print Day of the Week Using Enum and Switch

#include <stdio.h>

// Define enum for days
typedef enum {
    SUNDAY,
    MONDAY,
    TUESDAY,
    WEDNESDAY,
    THURSDAY,
    FRIDAY,
    SATURDAY
} Day;

int main() {
    Day today;

    int input;
    printf("Enter a number (0 for Sunday to 6 for Saturday): ");
    scanf("%d", &today);

    if (today < 0 || today > 6) {
        printf("Invalid day number!\n");
        return 1;
    }

    // Using switch to print the day name
    switch (today) {
        case SUNDAY:    printf("It's Sunday\n"); break;
        case MONDAY:    printf("It's Monday\n"); break;
        case TUESDAY:   printf("It's Tuesday\n"); break;
        case WEDNESDAY: printf("It's Wednesday\n"); break;
        case THURSDAY:  printf("It's Thursday\n"); break;
        case FRIDAY:    printf("It's Friday\n"); break;
        case SATURDAY:  printf("It's Saturday\n"); break;
    }

    return 0;
}
  

πŸ“˜ Explanation:

This C program maps numbers (0 to 6) to corresponding days of the week using enum and prints the result using a switch statement.

  • typedef enum creates a readable set of named constants for days.
  • User is prompted to enter a number between 0 and 6.
  • If the input is invalid, the program exits with an error message.
  • The switch statement matches the input to its corresponding weekday.

🧾 Sample Output:

Enter a number (0 for Sunday to 6 for Saturday): 2
It's Tuesday

Enter a number (0 for Sunday to 6 for Saturday): 7
In

Comments

Popular Posts

πŸŒ™