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
dayNumberand assigns it the value3(you can change it to test other days).The
switchstatement checks the value ofdayNumberand matches it with one of thecaselabels.Each
casecorresponds to a day of the week:1→ Monday2→ Tuesday3→ Wednesday4→ Thursday5→ Friday6→ Saturday7→ Sunday
The
breakstatement prevents execution from continuing into the next case once a match is found.If the number doesn’t match any case, the
defaultblock 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
dayNumberand assigns it the value3(you can change it to test other days).The
switchstatement checks the value ofdayNumberand matches it with one of thecaselabels.Each
casecorresponds to a day of the week:1→ Monday2→ Tuesday3→ Wednesday4→ Thursday5→ Friday6→ Saturday7→ Sunday
The
breakstatement prevents execution from continuing into the next case once a match is found.If the number doesn’t match any case, the
defaultblock runs and prints "Invalid number. Please enter a number from 1 to 7."Ends with
return 0;to indicate successful program completion.