59 lines
1.2 KiB
C
59 lines
1.2 KiB
C
|
// 编写一个程序,定义一个枚举(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;
|
|||
|
}
|