example of a simple C program that uses a `switch` statement to determine the day of the week based on a user-input number:
The switch statement is another way to control program flow based on the value of an expression. It's typically used when you have a single expression that you want to compare to multiple values.
In this program, the user enters a number, and the `switch` statement is used to determine and
print the corresponding day of the week. The `default` case is used to handle invalid inputs
#include <stdio.h>
int main() {
int day;
// Prompt the user to enter a number (1-7)
printf("Enter a number (1-7): ");
scanf("%d", &day);
switch (day) {
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 input. Please enter a number between 1 and 7.\n");
}
return 0;
}