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

59 lines
1.2 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 编写一个程序定义一个枚举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;
}