Solution: Day of the Week

The main() function uses a switch statement to print the day of the week based on a numeric value from 1 to 7.

  • Declares an integer variable dayNumber and assigns it the value 3 (you can change it to test other days).

  • The switch statement checks the value of dayNumber and matches it with one of the case labels.

  • Each case corresponds to a day of the week:

    • 1 → Monday

    • 2 → Tuesday

    • 3 → Wednesday

    • 4 → Thursday

    • 5 → Friday

    • 6 → Saturday

    • 7 → Sunday

  • The break statement prevents execution from continuing into the next case once a match is found.

  • If the number doesn’t match any case, the default block runs and prints "Invalid number. Please enter a number from 1 to 7."

  • Ends with return 0; to indicate successful program completion.

Solution: Day of the Week

The main() function uses a switch statement to print the day of the week based on a numeric value from 1 to 7.

  • Declares an integer variable dayNumber and assigns it the value 3 (you can change it to test other days).

  • The switch statement checks the value of dayNumber and matches it with one of the case labels.

  • Each case corresponds to a day of the week:

    • 1 → Monday

    • 2 → Tuesday

    • 3 → Wednesday

    • 4 → Thursday

    • 5 → Friday

    • 6 → Saturday

    • 7 → Sunday

  • The break statement prevents execution from continuing into the next case once a match is found.

  • If the number doesn’t match any case, the default block runs and prints "Invalid number. Please enter a number from 1 to 7."

  • Ends with return 0; to indicate successful program completion.