c语言用switch实现输入出生年份,输出属相
答案:3 悬赏:70 手机版
解决时间 2021-03-14 10:39
- 提问者网友:你挡着我发光了
- 2021-03-14 00:47
c语言用switch实现输入出生年份,输出属相
最佳答案
- 五星知识达人网友:冷風如刀
- 2021-03-14 02:11
#include
int main()
{
int year, t;
scanf ("%d", &year);
t = year%12;
switch(t){
case 0:
printf ("猴");break;
case 1:
printf ("鸡");break;
case 2:
printf ("狗");break;
case 3:
printf ("猪");break;
case 4:
printf ("鼠");break;
case 5:
printf ("牛");break;
case 6:
printf ("虎");break;
case 7:
printf ("兔");break;
case 8:
printf ("龙");break;
case 9:
printf ("蛇");break;
case 10:
printf ("马");break;
case 11:
printf ("羊");break;
}
return 0;
}
int main()
{
int year, t;
scanf ("%d", &year);
t = year%12;
switch(t){
case 0:
printf ("猴");break;
case 1:
printf ("鸡");break;
case 2:
printf ("狗");break;
case 3:
printf ("猪");break;
case 4:
printf ("鼠");break;
case 5:
printf ("牛");break;
case 6:
printf ("虎");break;
case 7:
printf ("兔");break;
case 8:
printf ("龙");break;
case 9:
printf ("蛇");break;
case 10:
printf ("马");break;
case 11:
printf ("羊");break;
}
return 0;
}
全部回答
- 1楼网友:雪起风沙痕
- 2021-03-14 03:54
#include
#include
int main(int argc, char *argv[])
{
int year;
scanf("%d",&year);
year=((int)fabs(year-2008))%12+1;//找到鼠年为基准点,2008年是鼠年
switch(year)
{
case 1: printf("Rat charm, 子鼠\n");break;
case 2: printf("Ox patient, 丑牛\n");break;
case 3: printf("Tiger sensitive, 寅虎\n");break;
case 4: printf("Rabbit articulate, 卯兔\n");break;
case 5: printf("Dragon healthy, 辰龙\n");break;
case 6: printf("Snake deep, 巳蛇\n");break;
case 7: printf("Horse popular, 午马\n");break;
case 8: printf("Goat elegant, 未羊\n");break;
case 9: printf("Monkey clever, 申猴\n");break;
case 10: printf("Rooster deep thinkers, 酉鸡\n");break;
case 11: printf("Dog loyalty, 戌狗\n");break;
case 12: printf("Pig chivalrous. 亥猪\n");break;
default: printf("Error!\n");break;
}
return 0;
}
#include
int main(int argc, char *argv[])
{
int year;
scanf("%d",&year);
year=((int)fabs(year-2008))%12+1;//找到鼠年为基准点,2008年是鼠年
switch(year)
{
case 1: printf("Rat charm, 子鼠\n");break;
case 2: printf("Ox patient, 丑牛\n");break;
case 3: printf("Tiger sensitive, 寅虎\n");break;
case 4: printf("Rabbit articulate, 卯兔\n");break;
case 5: printf("Dragon healthy, 辰龙\n");break;
case 6: printf("Snake deep, 巳蛇\n");break;
case 7: printf("Horse popular, 午马\n");break;
case 8: printf("Goat elegant, 未羊\n");break;
case 9: printf("Monkey clever, 申猴\n");break;
case 10: printf("Rooster deep thinkers, 酉鸡\n");break;
case 11: printf("Dog loyalty, 戌狗\n");break;
case 12: printf("Pig chivalrous. 亥猪\n");break;
default: printf("Error!\n");break;
}
return 0;
}
- 2楼网友:人類模型
- 2021-03-14 03:38
简单代码如下:
思路输入年份去对12取余得出余数就可以知道属相。
#include
int main()
{
int year, t;
scanf ("%d", &year);
t = year%12;
switch(t){
case 0:
printf ("猴");break;
case 1:
printf ("鸡");break;
case 2:
printf ("狗");break;
case 3:
printf ("猪");break;
case 4:
printf ("鼠");break;
case 5:
printf ("牛");break;
case 6:
printf ("虎");break;
case 7:
printf ("兔");break;
case 8:
printf ("龙");break;
case 9:
printf ("蛇");break;
case 10:
printf ("马");break;
case 11:
printf ("羊");break;
}
return 0;
}
思路输入年份去对12取余得出余数就可以知道属相。
#include
int main()
{
int year, t;
scanf ("%d", &year);
t = year%12;
switch(t){
case 0:
printf ("猴");break;
case 1:
printf ("鸡");break;
case 2:
printf ("狗");break;
case 3:
printf ("猪");break;
case 4:
printf ("鼠");break;
case 5:
printf ("牛");break;
case 6:
printf ("虎");break;
case 7:
printf ("兔");break;
case 8:
printf ("龙");break;
case 9:
printf ("蛇");break;
case 10:
printf ("马");break;
case 11:
printf ("羊");break;
}
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯