switch语句的应用--输出生肖
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int year;
printf("please enter a year:");
scanf("%d", &year);
switch (year %= 12) {
case 0:printf("monkey"); break;
case 1:printf("chicken"); break;
case 2:printf("dog"); break;
case 3:printf("pig"); break;
case 4:printf("mouse"); break;
case 5:printf("cattle"); break;
case 6:printf("tiger"); break;
case 7:printf("rabbit"); break;
case 8:printf("lo0ng"); break;
case 9:printf("snake"); break;
case 10:printf("horse"); break;
case 11:printf("sheep"); break;
default:printf("error"); break;
}
return 0;
}
运行结果截图: