qfedu-c-level/day12/homework/h7.c

59 lines
1.2 KiB
C
Raw Permalink Normal View History

2023-07-22 10:37:20 +08:00
// 编写一个程序定义一个枚举enum表示一周的每一天包括周一至周日。编写一个函数接受一个枚举值作为参数并根据枚举值打印出相应的星期几的名称。例如传递枚举值为2时函数应该打印出 "Tuesday"。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
};
void print_weekday(int day)
{
switch (day)
{
case Monday:
printf("Monday\n");
break;
case Tuesday:
printf("Tuesday\n");
break;
case Wednesday:
printf("Wednesday\n");
break;
case Thursday:
printf("Thursday\n");
break;
case Friday:
printf("Friday\n");
break;
case Saturday:
printf("Saturday\n");
break;
case Sunday:
printf("Sunday\n");
break;
default:
printf("Invalid day\n");
break;
}
}
int main()
{
print_weekday(Monday);
print_weekday(Tuesday);
print_weekday(Wednesday);
print_weekday(Thursday);
print_weekday(Friday);
print_weekday(Saturday);
print_weekday(Sunday);
return 0;
}