输入一个人的年份,查找出他所属的生肖,要求连续查询,按Y键继续判断,按其他键结束。
#include<stdio.h>void main()
{
int year,x,n;
char c='y';
while(c=='y'|| c=='Y')
scanf("%d",&year);
if(year>0)
{
x=year%12;
switch(x)
{
case 0:
printf("猴"\n");
break;
case 1:
printf("鸡\n");
break;
case 2:
printf("狗\n");
break;
case 3:
printf("猪\n");
break;
case 4:
printf("鼠\n");
break;
case 5:
printf("牛\n");
break;
case 6:
printf("虎\n"):
break;
case 7:
printf("兔\n");
break;
case 8:
printf("龙\n");
break;
case 9:
printf("蛇\n");
break;
case 10:
printf("马"\n);
break;
case 11:
printf("羊\n");
}
}
else
printf("请输入一个大于0的年份\n");
printf("是否要继续查询?继续查询请按<y>:");
getchar();
scanf("%c",&c);
}
}